ssh without a password but with key file

it is so comfortable to avoid using a password to get ssh access

On source machine – whre you wish to connect from we generate ssh key pair:

~$ cd .ssh

~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/lab4/.ssh/id_rsa): 103host
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in 103host.
Your public key has been saved in 103host.pub.
The key fingerprint is:
SHA256:cF+in9suF/dbtj8mUNQ+7OZ+HfbTrp7NUidvlLj1GTA lab4@ub1804
The key's randomart image is:
+---[RSA 2048]----+
| . |
| . . |
| . . . o o |
| o o o E + |
| S . . = o|
| . o..oO+|
| o .o**%|
| .o.o.@%|
| .+o.BO@|
+----[SHA256]-----+

So, we have had gotten key pair like these:

~/.ssh$ ls -la
total 36
drwx------ 2 lab4 lab4 4096 Jun 7 09:44 .
drwxr-xr-x 17 lab4 lab4 4096 Jun 7 09:38 ..
-rw------- 1 lab4 lab4 1675 Jun 7 09:44 id_rsa
-rw-r--r-- 1 lab4 lab4 393 Jun 7 09:43 id_rsa.pub

Now we have to copy *.pub key to the host to which we want to have got passwordless access:

~/.ssh$ ssh-copy-id root@192.168.1.103
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/lab4/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.1.103's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.1.103'"
and check to make sure that only the key(s) you wanted were added.

Do not foget to turn off passphrase every time when we run ssh connection:

~/.ssh$ ssh-add

Finaly, we have got ability to get access without password but with the key file:

~$ ssh root@192.168.1.103
Last login: Sun Jun 7 09:39:41 2020 from 192.168.1.101
[root@104 ~]#

Have You More questions? Please be free to ask us your questions in the
Dzhumaiev.Slack.com channel 🙂