You need to set up password-free login to build a Hadoop environment recently. The so-called password-free login actually refers to login through certificate authentication, use a public/private key authentication method for ssh login.
A simple explanation of the "Public/Private Key" authentication method: first, create a pair of public/private keys on the client (Public Key File :~ /. Ssh/id_rsa.pub; private key file :~ /. Ssh/id_rsa ). Then put the public key on the server (~ /. Ssh/authorized_keys) and keep the private key. when using ssh to log on, the ssh program will send a private key to match the public key on the server. if the match is successful, you can log on.
The configuration of Ubuntu and Cygwin is smooth, but many problems are encountered in Centos system configuration. Therefore, Centos (Centos5) is used as an example to describe how to configure certificate verification login. The specific steps are as follows:
1. confirm that the OpenSSH server and client have been installed in the system.
The installation steps are not described here, which is not the focus of this article.
2. Confirm the configuration file of the local sshd (root permission required)
$ Vi/etc/ssh/sshd_config
Find the following content and remove the annotator "#"
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile. ssh/authorized_keys
3. If the configuration file is modified, restart the sshd service (root permission required)
$ Vi/sbin/service sshd restart
4. log on to the system through ssh and run the test command:
$ Ssh localhost
Press enter and you will be prompted to enter the password, because at this time we have not generated a certificate
5. To generate a public/private key for a certificate:
$ Ssh-keygen-t dsa-p'-f ~ /. Ssh/id_dsa
$ Cat ~ /. Ssh/id_dsa.pub> ~ /. Ssh/authorized_keys
6. Test logon to ssh localhost:
$ Ssh localhost
Under normal circumstances, the login is successful, and some successful login information is displayed. If the login fails, please refer to the following general debugging steps.
7. General debugging steps
I failed to configure it. I still prompted to enter the password according to the above steps. Then, use ssh-v to display detailed login information to find the cause:
$ Ssh-v localhost
Press enter to display the detailed login information as follows:
...... Omitted
Debug1: Authentications that can continue: publickey, gssapi-with-mic, password
Debug1: Next authentication method: gssapi-with-mic
Debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
Debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
Debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
Debug1: Next authentication method: publickey
Debug1: Trying private key:/home/huaxia/. ssh/identity
Debug1: Trying private key:/home/huaxia/. ssh/id_rsa
Debug1: Offering public key:/home/huaxia/. ssh/id_dsa
Debug1: Authentications that can continue: publickey, gssapi-with-mic, password
Debug1: Next authentication method: password
Huaxia @ localhost's password:
At the same time, log on to the root user to view the system's log files:
$ Tail/var/log/secure-n 20
...... Omitted
Jul 13 11:21:05 shnap sshd [3955]: Accepted password for huaxia from 192.168.8.253 port 51837 ssh2
Jul 13 11:21:05 shnap sshd [3955]: pam_unix (sshd: session): session opened for user huaxia by (uid = 0)
Jul 13 11:21:47 shnap sshd [4024]: Connection closed by 127.0.0.1
Jul 13 11:25:28 shnap sshd [4150]: Authentication refused: bad ownership or modes for file/home/huaxia/. ssh/authorized_keys
Jul 13 11:25:28 shnap sshd [4150]: Authentication refused: bad ownership or modes for file/home/huaxia/. ssh/authorized_keys
Jul 13 11:26:30 shnap sshd [4151]: Connection closed by 127.0.0.1
...... Omitted
From the preceding log information, we can see that the file/home/huaxia/. ssh/authorized_keys has a permission error.
View the file details in/home/huaxia/. ssh/as follows:
$ Ls-lh ~ /. Ssh/
Total 16 K
-Rw-r -- 1 huaxia 602 07-13 authorized_keys
-Rw ------- 1 huaxia 672 07-13 id_dsa
-Rw-r -- 1 huaxia 602 07-13 id_dsa.pub
-Rw-r -- 1 huaxia 391 07-13 known_hosts
Modify the authorized_keys permission of the file (the permission setting is very important because insecure security settings make you unable to use the RSA function ):
$ Chmod 600 ~ /. Ssh/authorized_keys
Test again and log on as follows:
$ Ssh localhost
Last login: Wed Jul 13 14:04:06 2011 from 192.168.8.253
If this information is displayed, the local login without a password is successful.
8. log on to the remote server through authentication (the OpenSSH service of the remote server must be enabled)
Copy the locally produced key to the remote server (two methods)
Method 1:
$ Cat ~ /. Ssh/id_rsa.pub | ssh remote user name @ Remote Server ip 'cat-> ~ /. Ssh/authorized_keys'
Method 2:
Run the following command on the local machine:
$ Scp ~ /. Ssh/id_dsa.pub michael@192.168.8.148:/home/michael/
Log on to the remote server michael@192.168.8.148 and execute:
$ Cat id_dsa.pub >> ~ /. Ssh/authorized_keys
Remote logon to 192.168.8.148 on the local machine:
$ Ssh michael@192.168.8.148.
Linux michael-VirtualBox 2.6.35-22-generic # 33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux
Ubuntu 10.10
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
216 packages can be updated.
71 updates are security updates.
New release 'natty 'available.
Run 'do-release-upload' to upgrade to it.
Last login: Wed Jul 13 14:46:37 2011 from michael-virtualbox
Michael @ michael-VirtualBox :~ $
The logon is successful.
If the login test fails, you need to modify the authorized_keys permission of the file on the remote server 192.168.8.148 (permission setting is very important because insecure security settings make you unable to use the RSA function)
Chmod 600 ~ /. Ssh/authorized_keys