SSH key-based authentication

First, generate a key without password:

root@example:~# ssh-keygen -f ~/.ssh/id_rsa -q -P ""

You will see id_rsa and

root@example:~# ls -la .ssh
total 20
drwx------ 2 root root 4096 Nov 18 15:19 .
drwx------ 7 root root 4096 Apr 14  2018 ..
-rw------- 1 root root 1679 Nov 18 15:19 id_rsa
-rw-r--r-- 1 root root  401 Nov 18 15:19
-rw-r--r-- 1 root root  444 Sep 22  2017 known_hosts

Checking the public key contents

root@example:~# cat ~/.ssh/

Everything seems good. needs to be added into de ~/.ssh/authorized_keys of the remote server. Instead of doing it manually, let’s use the utility ssh-copy-id.

root@example:~# ssh-copy-id username@
/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
username@'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'username@'"
and check to make sure that only the key(s) you wanted were added.

Ok, now let’s test the ssh connection.

root@example:~# ssh username@
Linux 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Nov 18 15:15:12 2018 from
username@$ exit
Connection to closed.


Leave a Reply

Your email address will not be published. Required fields are marked *

Loading Facebook Comments ...
Loading Disqus Comments ...