Reprint please indicate the original address is: https://dongkelun.com/2018/04/05/sshConf/

The following uses three centos as an example. Their IP addresses are 192.168.44.138, 192.168.44.139, and 192.168.44.140, which correspond to the aliases master, Slave1, and slave2 respectively

1. Execute on each machine first

ssh-keygen -t rsa
Copy the code

Just keep pressing Enter and default is fine

2. Import the public key to the authentication file

Merge the contents of id_rsa.pub on the three machines and put them in authorized_keys. You can use the following command to do this, or you can copy the public keys of each machine into a file and then copy them into authorized_keys on each machine

2.1 Perform this operation on the Master

cd ~/.ssh
cat id_rsa.pub>>authorized_keys
Copy the code

(At this time, if it is equipped with a single machine, you can log in to the machine without secret. You can perform SSH localhost or SSH master authentication, as shown in the following figure)

If you cannot log in without password, the file permissions may be incorrect. Run the following command to verify the login

chmod 710 authorized_keys
Copy the code

Then upload master authorized_keys to.ssh directory on Slave1

scp -r authorized_keys root@slave1:~/.ssh
Copy the code

2.2 Running this command on Slave1

cd ~/.ssh
cat id_rsa.pub>>authorized_keys
scp -r authorized_keys root@slave2:~/.ssh
Copy the code

This step is to merge salve1’s ID_rsa. pub and authorized_keys from master into authorized_keys, and then upload authorized_keys to Slave2

2.3 Run this command on Slave2

cd ~/.ssh
cat id_rsa.pub>>authorized_keys
scp -r authorized_keys root@master:~/.ssh
scp -r authorized_keys root@slave1:~/.ssh
Copy the code

This step is to merge the contents of salve2’s ID_rsa. pub and slave1’s authorized_keys into authorized_keys, and then transfer authorized_keys to master and Slave1. At this point, authorized_keys on each machine contains the public key for all three machines, so verify on each machine that you can SSH to all three machines without encryption.

ssh master
ssh slave1
ssh slave2
Copy the code

If you do not need to enter a password, the configuration is successful.