This is the procedure to connect through ssh or run scp between serverA and serverB without a password.
Notice:
I am not responsible for any kind of damage. You choose to follow this guide at your own risk.
ServerA
First of all, you need to generate public and private keys.
WARNING! Make sure that you do not already have the keys, otherwise they will be replaced with the new ones. Check their presence in /root/.ssh/
Generation of the key:
root@kali:~# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): (press enter)
Enter same passphrase again: (press enter)
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:
77:c2:b2:59:7e:48:e1:bd:a9:c8:24:eb:ec:9a:18:2e root@kali
The key's randomart image is:
+–[ RSA 2048]—-+
| |
| |
| . |
| o o |
| S B o |
| O + o |
| . . + o + |
|E. o o = . o |
| .o o+= o . |
+—————–+
The RSA public key is contained in the file /root/.ssh/id_rsa.pub
root@kali:~# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCRlQnl7KMpOviNWRf9ckQWeCx59nUpc3kiZMkd9aaAMRZaVmA8BYs3UvZRvLr7fcxKAyZPWLvSEbV5YiQqkwq7/mgpnG7UsVLjxG5q00UF/QrqT97Mzo4w1WX+6kTtPIaJwqyjXRb+dn3E8NhKuAGwyTVz5CB3zoa7NiWBG/f+c8gtAeJXreABAn3biv3FJkCFVfQLBFWT90a/C3Da9qoRhqUlYqwn06NCrlsG1zzDy0ag5V7cxIkrRrEFiLTS/fsdSqEqmBCZGI2enSZYhmaCG11p5n0HMnjizPC3BxVEcD7UrZn5CizkVw0FqXCe54b4WLtFPfjR4Mu2th1hyCr root@kali
Copy the key in the clipboard.
ServerB
Login to the serverB as root and add the serverA RSA public key to /root/.ssh/authorized_keys file.
root@serverB:~# vi /root/.ssh/authorized_keys
Paste the public key inside this file. If there is another key file, just add it in the next line.
Here is an example of how authorized_keys should look like:
root@serverB:~# cat /root/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCRlQnl7KMpOviNWRf9ckQWeCx59nUpc3kiZMkd9aaAMRZaVmA8BYs3UvZRvLr7fcxKAyZPWLvSEbV5YiQqkwq7/mgpnG7UsVLjxG5q00UF/QrqT97Mzo4w1WX+6kTtPIaJwqyjXRb+dn3E8NhKuAGwyTVz5CB3zoa7NiWBG/f+c8gtAeJXreABAn3biv3FJkCFVfQLBFWT90a/C3Da9qoRhqUlYqwn06NCrlsG1zzDy0ag5V7cxIkrRrEFiLTS/fsdSqEqmBCZGI2enSZYhmaCG11p5n0HMnjizPC3BxVEcD7UrZn5CizkVw0FqXCe54b4WLtFPfjR4Mu2th1hyCr root@kali
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwWtdgN2UAgYC54h6z+g1fMeKMjQug5G27FfNtzS4Dw++Awf6hOh6QNfkMjPsGMzq4wg3l7fkz+9Baux83eT9x1Go/t0g0gi2tpssem1Vskvqqn3zwpktWPSTrZMWobK690h9RUVmdirMcLAB+iS47JQMapm+dI9AsD5tX6B4uSrZGAvXhYApj/CZrRcrrTYrdRE2WC9tFTC3XrzibxNqMqWXXkD+tqdnJSnMg/Zhbq3EyB8wPdCNd2e+QqdS3LRhYdW02Z1IskwxZp8SA6xbA5FGjCdxYyXcyijtqEAi2m+oAA1wrFtwnXWc+SGh6z32bZPFa1Fu38r4cSI7F0Cu9 root@debian
As you can see, there are 2 Public keys. It means that 2 servers can connect to ServerB without a password.
If you don't see .ssh in your root directory just create it with this command:
root@serverB:~# mkdir -p /root/.ssh/
If you don't see authorized_keys in your .ssh directory just create the one and paste the public key:
root@serverB:~# vi /root/.ssh/authorized_keys
Now it's time to test connection.
On serverA try to ssh in ServerB
root@kali:~# ssh root@serverB (or root@ip_Address)
root@serverB:~# (this is the serverB prompt)
This post is also available in: Italian