This article introduces the CentOS server two-way password free login; if you need, you can come and have a look!
(here, the two machines are represented by host 1 and host 2, and the two machines are equivalent.)
If host 1 wants to log in to host 2 without password, host 2 needs to be able to identify itself, which is recognized by public key and private key.
Generate the public key and private key on host 1, and pass the public key to host 2, so that when host 1 logs in to host 2, host 1 can let host 2 know itself with the private key
All servers / etc / SSH / sshd_ The following three lines of the config file are not commented
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys
give an example:
Two servers: 192.168.1.100
Password free login is divided into users. The following is an example of root user. SSH directory is under each user’s home directory.
Log in to 192.168.1.100.
Execute the command “SSH keygen – t RSA” and press all the way to the end. Private key ID will be generated under directory / root /. SSH /_ RSA and public key ID_ rsa.pub 。
Set the local public key ID_ rsa.pub Added to authorized of 192.168.1.102_ In the keys file.
At this time, you do not need a password to log in from 192.168.1.100 to 192.168.1.102.
To achieve two-way, continue with the following steps:
Log in to 192.168.1.102 and perform the similar steps above.
Modify / etc / SSH / sshd_ Need to restart sshd service after config file
Append public key to authorized of server_ In keys, do not overwrite.
The permission of the. SSH directory is 700, authorized_ The permissions for keys are 600.
Related reading:A tutorial of setting SSH password free login on the server of CentOS system