SSH 目录权限问题导致无法登录系统
2014-07-07 by dongnan
问题描述
ssh
远程登录服务器,发现 无法使用key
方式登陆,只能使用密码
方式登陆。
排错过程
使用 ssh -v
选项 发现只能使用口令方式登陆 ssh
服务器
debug1: Next authentication method: publickey
debug1: Trying private key: .ssh/mykey
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: password # 这里
查看日志,提示目录错误的权限关系:
tail /var/log/secure
#...省略
Authentication refused: bad ownership or modes for directory /home/zongming
检查目录权限,果然是用户家目录属主为 nobody
用户:
ll /home/
#...省略
drwxr-xr-x 8 nobody nobody 4096 Jun 10 00:31 zongming
解决方法
用户的家目录更改为正确的权限(属主与属组)
chown -R zongming.zongming /home/zongming/
验证
再次使用key
方式登陆服务器,正常:
debug1: Next authentication method: publickey
debug1: Trying private key: mykey
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).