CentOS Debian Security Shell

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
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@|

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

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

~/.ssh$ ssh-copy-id root@
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/lab4/.ssh/"
/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@'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@'"
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@
Last login: Sun Jun 7 09:39:41 2020 from
[root@104 ~]#

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

Leave a Reply