SSH/sshd免密登录设置无效解决方案
针对已经 copy 了 sshKey 到服务器上去的情况
🕐
可能原因1:
可能原因.ssh 目录权限,或者 authorized_keys 文件权限,执行如下命令
sudo chmod 700 ~/.ssh
sudo chmod 600 ~/.ssh/authorized_keys可能原因2:
如果方案1不起作用,尝试修改sshd_config文件中的 StrictModes 配置项
# step1
sudo vim /etc/ssh/sshd_config
# step2
# 把 yes 改成 StrictModes no
# step3
service ssh restart
# centos8
systemctl restart sshd.service
# step4 确认修改
cat /etc/ssh/sshd_config | grep StrictModes其它可能配置
vim /etc/ssh/sshd_config
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
# 确保没有禁止 root 登录公钥认证
PermitRootLogin prohibit-password
# 或者
PermitRootLogin yes
# (如果是 "no" 或 "without-password" 在某些旧版本行为不同,建议设为 yes 或 prohibit-password)
# 确保没有设置错误的 AllowUsers 或 DenyUsers
## ---- 改完记得重启
systemctl restart sshd.service