I had done password less shh authentication between multiple Linux box a couple of time but this time I had to do the same for normal user. I thought it would be same and actually it is the same but still there are few things which we might miss out and also it becomes a bit complicated and confusing as I did so for them I thought I should give some tips.
Question
You have to create a password less ssh connection between 3 Linux box for non root user i.e a normal user deepak.
Pre-requisites
User deepak should exist on all the 3 Linux box
Server details
Making password less connection from Server 1
On server 1
Login as user deepak
With the above command we have created a pair of public and private key using RSA type authentication.
Click the link to know more about RSA and DSA type of authentication
Now to create a password less ssh connection we need to copy id_rsa.pub to the remote server i.e server 2 and server 3
On server 2
Create .ssh directory in your home folder as it will not be present by default
NOTE: Make sure the permission on .ssh is 700
This next step you are appending the contents of the copied id_rsa.pub from server 1 into your authorized_keys file
NOTE: By default authorized_keys file will not be present. The below command will automatically create this file and append the output of cat into it.
NOTE: Make sure the permission on authorized_keys is 600
To view the contents of the contents of copied id_rsa.pub into authorized_keys
The same has to be done on server 3
On Server 3
NOTE: Make sure the permission on .ssh is 700
Using the above steps we have successfully created a password less authentication from
For the same has to be done from server 2 and server 3 with each other. So we will have to generate rsa keys on server 2 and server 3 as well.
Using the above steps we have successfully created a password less authentication from
So finally if you view the contents of your authorized_keys file in each user's home location you should be able to see something like this
It should have two entries for each server you have configured password less authentication using RSA encryption
IMPORTANT NOTE: For creating password less ssh authentication between multiple Linux machine using normal users make sure the two permissions are implemented or else the password less ssh authentication won't work
Permission 600 on authorized_keys file and
Permission 700 on .ssh directory
How to extract files to different directory using tar in Unix/Linux
How to preserve Symbolic links with tar command in Unix/Linux
How to give permission to user to run some commands in Linux
How to set environment (PATH) variable permanently in Linux
How to mount windows share on linux
Question
You have to create a password less ssh connection between 3 Linux box for non root user i.e a normal user deepak.
Pre-requisites
User deepak should exist on all the 3 Linux box
Server details
server 1
IP 192.168.0.101
server 2
IP 192.168.0.102
server 3
IP 192.168.0.103
Making password less connection from Server 1
On server 1
Login as user deepak
[deepak@server101 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/deepak/.ssh/id_rsa):
Created directory '/home/deepak/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/deepak/.ssh/id_rsa.
Your public key has been saved in /home/deepak/.ssh/id_rsa.pub.
The key fingerprint is:
f8:c3:78:b7:6d:89:01:3e:44:bc:3c:df:70:72:04:0c deepak@server101.example
With the above command we have created a pair of public and private key using RSA type authentication.
Click the link to know more about RSA and DSA type of authentication
Now to create a password less ssh connection we need to copy id_rsa.pub to the remote server i.e server 2 and server 3
[deepak@server101 ~]$ scp .ssh/id_rsa.pub 192.168.0.102:/home/deepak/
[deepak@server101 ~]$ scp .ssh/id_rsa.pub 192.168.0.103:/home/deepak/
On server 2
Create .ssh directory in your home folder as it will not be present by default
NOTE: Make sure the permission on .ssh is 700
[deepak@server102 ~]$ mkdir .ssh
[deepak@server102 ~]$ ls -al | grep .ssh
drwx------ 2 deepak deepak 4096 Jan 10 23:24 .ssh
This next step you are appending the contents of the copied id_rsa.pub from server 1 into your authorized_keys file
NOTE: By default authorized_keys file will not be present. The below command will automatically create this file and append the output of cat into it.
[deepak@server102 ~]$ cat id_rsa.pub >> .ssh/authorized_keys
NOTE: Make sure the permission on authorized_keys is 600
[deepak@server102 ~]$ ls -al .ssh/
-rw------- 1 deepak deepak 1616 Jan 11 04:21 authorized_keys
To view the contents of the contents of copied id_rsa.pub into authorized_keys
[deepak@server102 ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvaI3NDGXRQ922OJBh3nYmjkWwA6m0A7leiciIhXV1NxntM38K2Y8XIvCd3FPruguyB97P2r4mDpHPGtT5X4ZSWP8hrTxVcRmG8PfX0UelkquPikjC3Mj3XbQZC6H7rKLv4qwLR8PayBkdD004NIvhYAbE+5F5UCuDtOdcvoDDfV1pjVq44ZwyZyl1P3oui8GJpTkJ+isI0RASY3HOm50OTy+6XH/5HQLaPkc+0MMtc8D1y1xMqJ26cntsZLzEInuwbVSgUxuzJ/z9+j+Y4f7CJaEDC3fo8YFooQ8VxTdm5aXjeMMYu2mDpTfNn5GIXLCCwhk6kV5M3pdKpF7iPtQ== deepak@server101.example
The same has to be done on server 3
On Server 3
NOTE: Make sure the permission on .ssh is 700
[deepak@server103 ~]$ mkdir .ssh
[deepak@server103 ~]$ ls -al | grep .ssh
drwx------ 2 deepak deepak 4096 Jan 10 23:24 .ssh
[deepak@server103 ~]$ cat id_rsa.pub >> .ssh/authorized_keys
Restart your ssh services on Server 1 for the changes to take affect
# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
Using the above steps we have successfully created a password less authentication from
server 1 ------> server 2
server 1 ------> server 3
For the same has to be done from server 2 and server 3 with each other. So we will have to generate rsa keys on server 2 and server 3 as well.
Making password less connection from Server 2
On server 2
Login as user deepak
[deepak@server102 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/deepak/.ssh/id_rsa):
Created directory '/home/deepak/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/deepak/.ssh/id_rsa.
Your public key has been saved in /home/deepak/.ssh/id_rsa.pub.
The key fingerprint is:
n9:b3:87:34:ed:bg:12:bg:23:vf:23:vf:23:d3:3d:f4 deepak@server102.example
Now to create a password less ssh connection we need to copy id_rsa.pub to the remote server i.e server 1 and server 3
[deepak@server102 ~]$ scp .ssh/id_rsa.pub 192.168.0.101:/home/deepak/
[deepak@server102 ~]$ scp .ssh/id_rsa.pub 192.168.0.103:/home/deepak/
On server 1
This next step you are appending the contents of the copied id_rsa.pub from server 2 into your authorized_keys file[deepak@server101 ~]$ cat id_rsa.pub >> .ssh/authorized_keys
The same has to be done on server 3
On Server 3
[deepak@server103 ~]$ cat id_rsa.pub >> .ssh/authorized_keys
Restart your ssh services on Server 2 for the changes to take affect
# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
Using the above steps we have successfully created a password less authentication from
server 2 ------> server 1
server 2 ------> server 3
Making password less connection from Server 3
On server 3
Login as user deepak
[deepak@server103 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/deepak/.ssh/id_rsa):
Created directory '/home/deepak/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/deepak/.ssh/id_rsa.
Your public key has been saved in /home/deepak/.ssh/id_rsa.pub.
The key fingerprint is:
98:f4:98:f5:12:54:2d:5g:54:bg:5c:bg:12:fr:23:de deepak@server103.example
Now to create a password less ssh connection we need to copy id_rsa.pub to the remote server i.e server 1 and server 2
[deepak@server103 ~]$ scp .ssh/id_rsa.pub 192.168.0.101:/home/deepak/
[deepak@server103 ~]$ scp .ssh/id_rsa.pub 192.168.0.102:/home/deepak/
On server 1
This next step you are appending the contents of the copied id_rsa.pub from server 3 into your authorized_keys file
[deepak@server101 ~]$ cat id_rsa.pub >> .ssh/authorized_keys
The same has to be done on server 2
On Server 2
[deepak@server102 ~]$ cat id_rsa.pub >> .ssh/authorized_keys
Restart your ssh services on Server 3 for the changes to take affect
# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
Using the above steps we have successfully created a password less authentication from
server 3 ------> server 1
server 3 ------> server 2
So finally if you view the contents of your authorized_keys file in each user's home location you should be able to see something like this
[deepak@server103 ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2pKXrVmdyJrVlds5qfuTMa5TugOb6loZTUkijgkvNRztSZ1AFesXWwMS+JaifQaX6bqdkWeZU5lCQeBHrNrc7wTFtChMx85so6S46o9Nfv0Q5qk7e2a0O2rLtww8NlBDp4b1tMU1HXFIIJDM0KwlvSlBtYIHqufvPxzIiK3R1kp87ZGMDg+sPHFOm8DRut0QFCV65174XM3GaMIhksN+xs5V53JKBp70rLhtTikPYb7nzmWIGqs8W6N/YsZpTxEmGhOLwGznY079aEIVLIotSqPt7t0s+vh/lyaImCOUzJiNGqkMXjCLo40QA2YGCc4yetJ4DxBkPTwVnlRmUYZRmw== deepak@server101.example
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvaI3NDGXRQ922OJBh3nYmjkWwA6m0A7leiciIhXV1NxntM38K2Y8XIvCd3FPruguyB97P2r4mDpHPGtT5X4ZSWP8hrTxVcRmG8PfX0UelkquPikjC3Mj3XbQZpC6H7rKLv4qwLR8PayBkdD004NIvhYAbE+5F5UCuDtOdcvoDDfV1pjVq44ZwyZyl1P3oui8GJpTkJ+iscI0RASY3HOm50OTy+6XH/5HQLaPkc+0MMtc8D1y1xMqJ26cntsZLzEInuwbVSgUxuzJ/z9+j+Y4f7CJaEDC3fo8YFooQ8VxTdm5aXjeMMYu2mDpTfNn5GIXLCCwhk6kV5M3pdKpF7iPtQ== deepak@server102.example
It should have two entries for each server you have configured password less authentication using RSA encryption
IMPORTANT NOTE: For creating password less ssh authentication between multiple Linux machine using normal users make sure the two permissions are implemented or else the password less ssh authentication won't work
Permission 600 on authorized_keys file and
Permission 700 on .ssh directory
Follow the below links for more tutorials
Multiple connections to a server or shared resource by same userHow to extract files to different directory using tar in Unix/Linux
How to preserve Symbolic links with tar command in Unix/Linux
How to give permission to user to run some commands in Linux
How to set environment (PATH) variable permanently in Linux
How to mount windows share on linux
How to give normal user root privileges using sudo in Linux/Unix
How to do Ethernet/NIC bonding/teaming in Red Hat Linux
How to install/uninstall/upgrade rpm package with/without dependencies
How to do Ethernet/NIC bonding/teaming in Red Hat Linux
How to install/uninstall/upgrade rpm package with/without dependencies