In this article we will show you how to setup password-less login using ssh keys to connect to remote Linux servers without entering password. Using Password-less login with SSH keys will increase the trust between two Linux servers for easy file synchronization or transfer. SSH Password-less login is one of the best way to automate tasks such as automatic backups with scripts, synchronization files using scp and remote command execution. Let's follow the steps in creating the password-less connection.
yum install ssh
......
.....
[root@xxxx1 staging]# ssh-keygen -t dsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0a:2d:de:92:c0:04:2e:2d:f9:b5:f5:ea:a4:84:e9:15 root@xxxx1
The key's randomart image is:
+--[ RSA 2048]----+
|. |
|.+ |
|+.o . . |
|.= . + . |
| + E . S |
| = * o |
| o * = |
| . o = |
| . . . |
+-----------------+
[root@xxxx1 staging]# cd ~
[root@xxxx1 ~]# ls -la .ssh
total 20
drwx------. 2 root root 4096 Sep 30 12:45 .
dr-xr-x---. 6 root root 4096 Sep 30 12:44 ..
-rw-------. 1 root root 1675 Sep 30 12:45 id_rsa
-rw-r--r--. 1 root root 393 Sep 30 12:45 id_rsa.pub
-rw-r--r--. 1 root root 408 Sep 30 12:44 known_hosts
[root@xxxx1 ~]# chmod 755 .ssh
[root@xxxx1 ~]# cd .ssh
[root@xxxx1 .ssh]# touch authorized_keys
[root@xxxx1 .ssh]# cat id_rsa.pub > authorized_keys
[root@xxxx1 .ssh]# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxVB3FtzWPvYUb+vMZp77dfFMU81X5rQsPBmMGQM8ib7POx.......== root@xxxx1
[root@xxxx1 .ssh]#
[root@xxxx1 .ssh]# chmod 600 authorized_keys
[root@xxxx1 .ssh]# ll
total 16
-rw-------. 1 root root 393 Sep 30 13:05 authorized_keys
-rw-------. 1 root root 1675 Sep 30 12:45 id_rsa
-rw-r--r--. 1 root root 393 Sep 30 12:45 id_rsa.pub
-rw-r--r--. 1 root root 408 Sep 30 12:44 known_hosts
[root@xxxx2 .ssh]# ssh root@xxxx1
The authenticity of host 'xxxx1 (11.222.33.11)' can't be established.
RSA key fingerprint is f9:2f:83:81:cc:37:10:be:d8:73:87:a8:a5:50:78:22.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'xxxx1,11.222.33.11' (RSA) to the list of known hosts.
Last login: Mon Sep 30 12:36:29 2013 from host
[root@xxxx1 ~]#