Achieve password-less login using SSH

Source: Internet
Author: User

1. preparations:

Check whether the SSH service and rsync service are installed (Rsync is a remote data synchronization tool that allows you to quickly synchronize files between multiple hosts through LAN/WLAN)

Rpm-Qa | grep OpenSSH

Rpm-Qa | grep rsync

Display in my centos 5.6:
Www.2cto.com

 

If not, run the following command:

Yum Install SSH

Yum install rsync

Service sshd restart start service
Www.2cto.com

 

1. Principles of SSH password-less Authentication

As a client, master must implement password-free public key authentication. When connecting to the server salve, a key pair must be generated on the master, including a public key and a private key, then, copy the public key to all salve instances. When the master node is linked to salve through SSH, salve generates a random number and encrypts the random number with the public key of the master node and sends it to the master node. After the master receives the number of encrypted data, it decrypts it with the private key and returns the number of decrypted data to salve. After confirming that the number of decrypted data is correct, the master is allowed to connect. This is a public key authentication process, during which you do not need to manually enter the password, the important process is to copy the Public Key generated on the master to salve.
 

2. Actual Operation Process

3.1 Use the master node to log on to salve without a password

1> Log On As A root user and change the SSH configuration file.

VI/etc/ssh/sshd_config

 

Rsaauthentication yes # enable RSA Authentication

Pubkeyauthentication yes # enable public key/private key pair Authentication

Authorizedkeysfile. Ssh/authorized_keys # public key file path

Restart the SSH service: Service sshd restart
Www.2cto.com

2> Log On As A new hadoop user

Su-hadoop

Ssh-keygen-t rsa: generate a key file. All files are generated by default. The default storage location after the key file is/home/hadoop (your user name)/. Ssh.

 

View the generated file: the two key pairs under LL. SSH are generated.

 

Add id_rsa.pub to the authorization key: CAT id_rsa.pub> authorized_keys

 

Modify the authorized_keys permission (this step is very heavy, otherwise, the password is still required for SSH)

Chmod 600 authorized_keys

 

Check whether the local machine can be accessed through SSH without a password: SSH localhost

 

OK. The above shows that the local logon is successful.

The next step is to copy the master's public key id_rsa.pub to salve and add it to the authorized key.

SCP ~ /. Ssh/id_rsa.pub hadoop@192.168.171.133 :~ /

 

Because no authentication has been added for the first login, this time you will still be prompted to enter the password

Log on to the salve node as hadoop (note that the SSH configuration is modified as root based on the previous suggestions. The method is the same as above)

 

Confirm that the file exists

If not. create a folder by Using SSH. ssh, and change the permission to 700. This step is very important because the default. the permission of the SSH folder is 700. If you do not modify the permission manually, it cannot be successfully created.

Id_rsa.pub is added to the authorization key:

Mkdir. SSH

Chmod 700. SSH

Cat ~ /Id_rsa.pub> ~ /. Ssh/authorized_keys

Modify authorized_keys to 600

Chmod 600 ~ /. Ssh/authorized_keys

Go to the master node and check whether you can log on to the salve node:

SSH 192.168.171.20.

 

OK. You have successfully logged on to salve without a password on the master node.

3.1.2 you can also generate a key pair on the savle and add it to master authorization to achieve mutual login without a password.

Ssh-keygen-T RSA

Cat ~ /. Ssh/id_rsa.pub> ~ /. Ssh/authorized_keys

SCP ~ /. Ssh/id_rsa.pub hadoop@192.168.171.131 :~ /

Cat ~ /Id_rsa.pub> ~ /. Ssh/authorized_keys

Verify logon.

Notes: www.2cto.com

1> the SSH configuration file must be modified and restarted after modification.

2> You must append the authentication file: CAT ~ /. Ssh/id_rsa.pub> ~ /. Ssh/authorized_keys

3> you must change the authorized_keys File Permission to 600.

4> If the SSH file is manually created, the permission must be changed to 700.
 

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.