点击上方"walkingcloud"关注,并选择"星标"公众号
记一次SSH免密码登陆时出现bad ownership or modes for file报错的解决过程
问题场景前置条件
例如A服务器192.168.31.232远程到服务器B192.168.31.127,做了SSH免密登录
ssh-keygen -b 4096
ssh-copy-id [email protected]
ssh [email protected]
这时无需输入密码可以直接免密登录
(图片可点击放大查看)
(图片可点击放大查看)
1、但后来出现ssh登录仍要输入密码的情况
ssh [email protected]
(图片可点击放大查看)
2、在客户端ssh -v 命令未能找到原因
(图片可点击放大查看)
3、在SSH服务器端查看secure日志继续排查
可以看到ssh client登录时服务器端有如下报错日志
sshd[3039]: Authentication refused: bad ownership or modes for file /root/.ssh/authorized_keys
(图片可点击放大查看)
4、问题原因
ls -al /root/.ssh/authorized_keys
文件的属主变成了非root用户,导致该问题出现
(图片可点击放大查看)
man ssh查看该解释
~/.ssh/authorized_keys
Lists the public keys (DSA, ECDSA, Ed25519, RSA) that can be used for logging in as this user. The format of this file is described in the sshd(8) manual
page. This file is not highly sensitive, but the recommended permissions are read/write for the user, and not accessible by others.
(图片可点击放大查看)
5、解决方法
chown -R root:root /root
(图片可点击放大查看)
6、验证问题是否解决
可以看到SSH免密登录恢复正常
(图片可点击放大查看)
原文始发于微信公众号(WalkingCloud):SSH免密码登陆时出现bad ownership or modes for file报错的解决过程
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论