如何排查
1、
ssh -vv root@192.168.1.1
根据debug信息分析原因
2、
主机开启一个ssh
/usr/sbin/sshd -d -p 10705
ps:注意开启端口,或者暂时关闭防火墙
客户端连接
ssh -vv 192.168.1.1 -p 10705
查看主机的输出信息
解决方案
我这边的原因是因为
Authentication refused: bad ownership or modes for directory /root
ssh 为了保证通信安全,防止 key 被篡改或窃取,对目录和文件的权限要求相当严格。
所以直接执行一下命令
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
连接成功
其他解决方案
有可能是未开启公钥认证
vi /etc/ssh/sshd_config
修改
PubkeyAuthentication yes
RSAAuthentication yes
保存后重启
systemctl restart sshd
参考:https://help.ubuntu.com/community/SSH/OpenSSH/Keys
https://www.imooc.com/article/21437