Plainnotes

配了密钥登录,为什么还要密码

2026-03-04 · 3 分钟系统

authorized_keys 放好了,ssh -i 指定了私钥,还是提示输密码。用 ssh -vvv 看,搜索 Offering public key 和 Authentications that can continue。

常见原因:

一,权限。~/.ssh 必须 700,authorized_keys 600,家目录不能对 group/other 可写。sshd 会直接忽略权限过宽的文件,且在日志里只写一行 Authentication refused: bad ownership or modes。

二,sshd_config 里 PubkeyAuthentication no,或者 AuthorizedKeysFile 指向了别处。

三,SELinux 的上下文不对(CentOS 常见),restorecon -Rv ~/.ssh 能修。

四,用的是 root,但 PermitRootLogin prohibit-password 之外还配了 AllowUsers,没包含 root。