This is the procedure to connect via ssh or scp serverA and serverB without entering the password

Notice:
I am not responsible for any damages. If you follow this guide it is at your own risk.
ServerA
First you need to generate the public and private keys
ATTENTION! Make sure you do not already have the keys otherwise they will be replaced with the new ones. Check their presence in /root/.ssh/
Key generation:
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): (premere invio)
Enter same passphrase again: (premere invio)
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 to the clipboard.
ServerB
Loggarsi al ServerB come root e copiare la chiave pubblica RSA del ServerA nel file /root/.ssh/authorized_keys del serverB.
root@serverB:~# vi /root/.ssh/authorized_keys
paste the public key into this file. If another key exists then copy it to the next line.
This is an example of what the authorized_keys file 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 via ssh or scp without password to ServerB.
If there is no .ssh in the root directory then you can create it with the following command:
root@serverB:~# mkdir -p /root/.ssh/
If there is no authorized_keys in the .ssh directory then you can create it and then copy the public key:
root@serverB:~# vi /root/.ssh/authorized_keys
Now you can try the connection:
On serverA try to ssh to ServerB
root@kali:~# ssh root@serverB (or root@ip_address)
root@serverB:~# (this is the prompt of ServerB)
Use the share button below if you liked it.
Your click is my virtual high-five.