SSH password-less log in method.
Let’s imagine that we have 2 hosts.
- Host A with user1 is your local host from which you will connect to remote.
- Host B with user2 is remote host where you want to log in as user2.
Run
ssh-keygen
as user1 on Host A to generate keys unless old one is exist. When I will be prompted to enter passphrase just keep it blank. This command generate RSA key with long in 2048 bit:
ssh-keygen -b 2048 Generating public/private rsa key pair. Enter file in which to save the key (/home/user1/.ssh/id_rsa): /home/user1/.ssh/id_rsa already exists. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/user1/.ssh/id_rsa. Your public key has been saved in /home/user1/.ssh/id_rsa.pub. The key fingerprint is: 9e:f0:44:4a:e2:81:72:02:0b:3c:b5:3d:be:a7:c2:95 user1@host_a The key's randomart image is: +--[ RSA 2048]----+ ... +-----------------+
After it’s done check content of your id_rsa.pub file:
host_a:~# cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzU6SlO7EZksPGmLTz3EcMpFQXME9otJ4vWqQ1Nnzd0g0FX5MS /H1m2xJWCLfgsWTWyOP7hHQufPrzY5kqJkeF0tgOSPHnzDQt4YBE1Xi0ihR/cDK+KHOlIFG4kHlEs/ThTDpD0mwgBC755Tu5g2GOW3ogsrViZbyfa72HJQaEbISZwfiPnJUwmtGJ/+PQiEoN8cgK1zrk8oVnlguK0V52ZygFuvNKd6jmKIiDKOcQ2ZIobu6jYVd/Nit1gg+9llbuAdXDFn24AdNHatBzvlwb76yYa/ZAwZQKzytWca0NnMMwMeQ== user1@host_a
Copy it and log in remote Host B as user2. And append it to authorized_keys file:
$ cat >> /home/grytsenko/.ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzU6SlO7EZksPGmLTz3EcMpFQXME9otJ4vWqQ1Nnzd0g0FX5MS /H1m2xJWCLfgsWTWyOP7hHQufPrzY5kqJkeF0tgOSPHnzDQt4YBE1Xi0ihR/cDK+KHOlIFG4kHlEs/ThTDpD0mwgBC755Tu5g2GOW3ogsrViZbyfa72HJQaEbISZwfiPnJUwmtGJ/+PQiEoN8cgK1zrk8oVnlguK0V52ZygFuvNKd6jmKIiDKOcQ2ZIobu6jYVd/Nit1gg+9llbuAdXDFn24AdNHatBzvlwb76yYa/ZAwZQKzytWca0NnMMwMeQ== user1@host_a
Set proper permissions for file:
user2@host_b:~$ chmod 600 ~/.ssh/authorized_keys
Now you are ready to log in without password from Host A:
host_a~# ssh -p 443 user2@host_b Linux host_b 2.6.18-5-686 #1 SMP Fri Jun 1 00:47:00 UTC 2007 i686
That’s all folks:).