关于SSH不能自动登录的问题

十一月 1st, 2010 发表评论 阅读评论

今天在一台电脑上配置用SSH自动登录(即不输入密码登录),但总是失败,明明在另一台机子上可以成功,检查了半天服务器上的sshd_config都没有问题。公钥私钥都已经配好了,authorized_keys也生成了,但就是不管用。于是检查了一下日志,先是Client端的,用ssh -vvv user@219.aaa.bbb.ccc显示如下内容:
(前面略去)
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/user/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 368 bytes for a total of 1495
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user/.ssh/identity
debug3: no such identity: /home/user/.ssh/identity
debug1: Trying private key: /home/user/.ssh/id_dsa
debug3: no such identity: /home/user/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
user@219.aaa.bbb.ccc's password:

能看出来客户端已经发送了自己的密钥id_rsa给服务器,但是服务器那边没有接受,于是又查看了一下服务器上的日志,位于/var/log/secure。里面有这样一行:

 

Nov  1 12:17:16 localhost sshd[29659]: Authentication refused: bad ownership or modes for directory /home/user/.ssh

看来是.ssh目录的权限有问题。于是查看了一下,目录的权限是775,而另一台机器上是755。于是把.ssh目录和authorized_keys的权限都改成755。终于成功。

 

分类: 标签: ssh