Configure SSH password-less logon in Linux

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.