How to add ssh password-free login to multiple servers

1. Map IPs by name in multiple hosts (take three hosts as an example)

vim /etc/hosts

xxx.xxx.xxx.xxx node1

xxx.xxx.xxx.xxx node2

xxx.xxx.xxx.xxx node3

Do the above operations on all three hosts.

Then refresh the network card on the three hosts respectively service network restart

Then ping node1, node2, node3 respectively, we can see that all can be pinged

Then execute the following commands on the three hosts respectively

ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa Generate the secret key
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys Generate the public key for password-free login

At this point, we can log in to the machine without a password on a single server!

Take the password-free login of node1 to node2 as an example, the others are the same, pay attention to the login direction!

Go to the root directory of node2

cd

scp root@'node1':~/.ssh/id_dsa.pub ./

enter password

id_dsa.pub has been copied over

cat id_dsa.pub >> ~/.ssh/authorized_keys Append node1's public key to the authorized_keys file

Return to the node1 machine, ssh node2, at this point we can see that node1 no longer needs to enter a password to log in to node2, and the password-free login is successful! The other methods are the same!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325331344&siteId=291194637