用ssh-keygen -t rsa 生成公钥和私钥文件
1.[hduser@levin .ssh]$ ssh-keygen -t rsa
[hduser@levin .ssh]$ ls -l
-rw——- 1 hduser hduser 1675 Mar 21 09:38 id_rsa
-rw-r–r– 1 hduser hduser 394 Mar 21 09:38 id_rsa.pub
2.用命令cat id_rsa.pub >> authorized_keys
[hduser@levin .ssh]$ ls -l
total 16
-rw-rw-r– 1 hduser hduser 394 Mar 21 09:38 authorized_keys
-rw——- 1 hduser hduser 1675 Mar 21 09:38 id_rsa
-rw-r–r– 1 hduser hduser 394 Mar 21 09:38 id_rsa.pub
3.正常用root用户或者非本机都可以正常登陆,但在用hduser用户是不能登陆,提示以下错误信息
[hduser@levin .ssh]$ ssh levin -v
debug1: Unspecified GSS failure. Minor code may provide more information
Credentials cache file ‘/tmp/krb5cc_500’ not found
debug1: Next authentication method: publickey
debug1: Trying private key: /home/hduser/.ssh/identity
debug1: Offering public key: /home/hduser/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/hduser/.ssh/id_dsa
debug1: Next authentication method: password
hduser@levin’s password:
ssh 免密码登陆失败,由于authorized_keys权限 问题。需要更改authorized_keys文件权限
4.更改authorized_keys文件权限
[hduser@levin .ssh]$ chmod 710 authorized_keys
[hduser@levin .ssh]$ ls -l
total 16
-rwx–x— 1 hduser hduser 394 Mar 21 09:38 authorized_keys
-rw——- 1 hduser hduser 1675 Mar 21 09:38 id_rsa
-rw-r–r– 1 hduser hduser 394 Mar 21 09:38 id_rsa.pub
-rw-r–r– 1 hduser hduser 401 Mar 21 09:38 known_hosts
authorized_keys文件权限已更改过来。
5.最后成功登录
[hduser@levin .ssh]$ ssh levin
Last login: Thu Mar 20 16:31:24 2014 from levin
来源URL:http://blog.csdn.net/lizhongren/article/details/21695875