记一次ssh免密登录失败的debug经历

1. 问题

设置ssh免密登陆时,发现有一些机器正常登陆,有一些机器提示错误信息:public-key authentication with the server for user gzsun failed. Please verify username and public/private key pair.


2. 解决

2.1 查看ssh日志,debug

在本地,使用ssh客户端登陆。

# ssh root@xxxx -p 2222 -v

在ssh服务端,查看日志。

# more /var/log/secure 

其中,显示用户的.ssh文件夹和用户主目录/home/jack没有权限。

Authentication refused: bad ownership or modes for directory /home/jack/.ssh
Authentication refused: bad ownership or modes for directory /home/jack/.ssh
Authentication refused: bad ownership or modes for directory /home/jack/.ssh
error: Received disconnect from 36.111.140.26 port 59536:14: Unable to authenticate using any of the configured authentication methods.  [preauth]

Authentication refused: bad ownership or modes for directory /home/jack
Authentication refused: bad ownership or modes for directory /home/jack
Authentication refused: bad ownership or modes for directory /home/jack
error: Received disconnect from 36.111.140.26 port 62668:14: Unable to authenticate using any of the configured authentication methods.  [preauth]

因为/home/jack/.ssh目录只供属主用户读写执行,其他用户都不可以,这就导致了
/home/jack/.ssh/authorized_keys无法被读取,也就导致了ssh认证不通过。


2.2 解决方法

解决方法很简单,检测相关目录权限,把不符合要求的按要求设置权限即可。

# chmod 700 /home/jack/

# chmod 700 /home/jack/.ssh

# chmod 600 /home/jack/.ssh/authorized_keys
# chown -R jack:jack /home/jack

注:无论什么工具,debug一定要好好看文档。


3. 参考文章

https://wiki.centos.org/HowTos/Network/SecuringSSH

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值