Configure SSH password-less logon in Linux
The following describes how to configure two hosts to log on without a password. The local host name is master, and the sub-host name is slave1.
1. Configure the Host Name
Modify the host names of the two machines as master and slave1 respectively. Specific Method: Modify the Host Name (hostname) of CentOS)
2. Configure hosts
Perform the following operations on both hosts. The current server is placed on the first line.
vi /etc/hosts
Add 2 rows
115.10.20.1 master // the IP address of the corresponding host 115.10.20.2 slave1
3. Generate a Public Key
(1) Input
Cd ~ // Ssh/ssh-keygen-t rsa // press enter to copy the public key to the authorized_keys file.
(2) Input in slave1
Cd ~ // Ssh/ssh-keygen-t rsa // press enter until scp id_rsa.pub root @ master :~ // Ssh/id_rsa.pub_slave1 // copy the public key to the master
(3) Input
Cat id_rsa.pub_slave1> authorized_keys // append the public key of slave1 to authorized_keys (which already contains the master Public Key) scp authorized_keys root @ slave1 :~ // Ssh // copy the authorized_keys file containing the public keys of two hosts to slave1
4. Modify permissions and configurations
Run the following command on two hosts:
chmod 700 ~/.sshchmod 644 ~/.ssh/authorized_keysvi /etc/ssh/sshd_config
Remove the comments in the following sections of sshd_config:
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys
Restart the ssh service:service sshd restart
5. Test
Use ssh slave1 and ssh localhost on the master to test whether no password is required. Use ssh master on slave1 and use ssh localhost to test whether no password is required.