现象描述: 1. 配置完服务器端公钥和本地的私钥之后,ssh登录始终会让输入密码,用ssh -vvv root@ip 查看发现发送密钥之后就没反应了。
本机debug info:
debug1: Trying private key: C:\Users\wangc/.ssh/id_xxxx (私钥文件)
debug3: ****
debug3: ****
debug3: ****
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
环境:
服务器端armbian 5.7
本地 win10
解决思路:1. 查看服务端日志
# 客户端shell下查看日志
journalctl -f # 实时查看日志
# 本地win10 重新登录
ssh -vvv root@ip
## 结果返回
Feb 24 12:59:13 aml sshd[31573]: rexec line 39: Deprecated option RSAAuthentication
Feb 24 12:59:13 aml sshd[31573]: reprocess config line 39: Deprecated option RSAAuthentication
Feb 24 12:59:13 aml sshd[31573]: Authentication refused: bad ownership or modes for directory /root
发现是root文件夹权限的问题
解决方案
chmod 0750 root/ -R
## 注意这里我其他文件的权限没问题。一般来说还要注意.ssh文件和文件里面内容的权限
因为sshd为了安全,对属主的目录和文件权限有所要求。如果权限不对,则ssh的免密码登陆不生效。
用户目录权限为 755 或者 700,就是不能是77x、777,需要保障other用户不能有w权限
.ssh目录权限一般为755或者700。
rsa_id.pub 及authorized_keys权限一般为644
rsa_id权限必须为600