Authentication refused: bad ownership or modes for directory /root

本文详细记录了在Centos7上配置SSH免密登录时遇到的问题及解决过程。针对一台主机虽已配置公钥,但仍需输入密码的情况,通过查看日志定位到文件权限错误,并成功通过调整/root目录权限至700解决了问题。

背景:

Centos7 成功配置免密登录,其它主机没有问题,有一台主机配置的公钥没有问题,但是登录还是需要输入密码,

查看日志( /var/log/secure),报错:Apr 10 15:49:39 node32 sshd[30988]: Authentication refused: bad ownership or modes for directory /root

解决:

是文件权限问题,发现 /root  目录权限为 777,  .ssh/  目录权限为700 ,  authorized_keys 文件 权限为600

将 /root 权限修改为 700 , 可以成功免密连接。

参考:

1.https://blog.youkuaiyun.com/u011350541/article/details/81070275

2.https://blog.youkuaiyun.com/u011350541/article/details/54906181

3.https://blog.youkuaiyun.com/Joseph25/article/details/89352514

4.https://www.cnblogs.com/pinganzi/p/5151476.html

关于如何设置免密登录,参考:

1.https://blog.youkuaiyun.com/abcdu1/article/details/105436694

2.https://blog.youkuaiyun.com/axing2015/article/details/83754785

3.https://blog.youkuaiyun.com/mo_ing/article/details/81042816

测试 SSH 基础连接 # 使用相同参数测试连接 ssh -v -p [端口] -i ~/.ssh/id_rsa [用户名]@[服务器IP] 观察 debug1: Authentications that can continue 后的错误提示: debug1: load_hostkeys: fopen /Users/jolinjiang/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /Users/jolinjiang/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: checking without port identifier debug1: load_hostkeys: fopen /Users/jolinjiang/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /Users/jolinjiang/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: hostkeys_find_by_key_hostfile: hostkeys file /Users/jolinjiang/.ssh/known_hosts does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /Users/jolinjiang/.ssh/known_hosts2 does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /etc/ssh/ssh_known_hosts does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /etc/ssh/ssh_known_hosts2 does not exist The authenticity of host '[fox-telemarket.starklotus.com]:36000 ([149.129.235.174]:36000)' can't be established. ED25519 key fingerprint is SHA256:/g3xmRHaPBpl4W5WUIcgHNyzPKjt5gCadvKC/8hlTZY. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[fox-telemarket.starklotus.com]:36000' (ED25519) to the list of known hosts. debug1: rekey out after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 4294967296 blocks debug1: SSH2_MSG_EXT_INFO received debug1: kex_ext_info_client_parse: server-sig-algs=<rsa-sha2-256,rsa-sha2-512> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: Next authentication method: publickey debug1: get_agent_identities: bound agent to hostkey debug1: get_agent_identities: agent returned 1 keys debug1: Will attempt key: /Users/jolinjiang/.ssh/id_rsa RSA SHA256:HnRtogpLB7+VvzDy1C4Z/8RX5duqmYaBju7QMAC70hA explicit agent debug1: Will attempt key: /Users/jolinjiang/.ssh/id_rsa RSA SHA256:HnRtogpLB7+VvzDy1C4Z/8RX5duqmYaBju7QMAC70hA explicit debug1: Offering public key: /Users/jolinjiang/.ssh/id_rsa RSA SHA256:HnRtogpLB7+VvzDy1C4Z/8RX5duqmYaBju7QMAC70hA explicit agent debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: Offering public key: /Users/jolinjiang/.ssh/id_rsa RSA SHA256:HnRtogpLB7+VvzDy1C4Z/8RX5duqmYaBju7QMAC70hA explicit debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: No more authentication methods to try. jolinjiang@fox-telemarket.starklotus.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
最新发布
08-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值