SSH 公钥登录失败的定位与修复
ssh 报 Permission denied (publickey),密码登录可能正常但公钥不行。常见于权限、属主、sshd 配置或 SELinux 上下文。
ssh -vvv user@host
ls -ld ~ ~/.ssh
ls -l ~/.ssh/authorized_keys
stat -c '%U %G %a %n' ~/.ssh ~/.ssh/authorized_keys
sshd -T | grep -E 'pubkey|authorizedkeys|permitroot|passwordauth'
journalctl -u sshd --since '10 min ago'
ls -Z ~/.ssh/authorized_keys
.ssh 或 authorized_keys 权限过宽(应为 700/600)。AuthorizedKeysFile。AllowUsers/Match 限制。chmod 700 ~/.ssh、chmod 600 ~/.ssh/authorized_keys。chown -R user:user ~/.ssh。sshd_config 的 PubkeyAuthentication、AuthorizedKeysFile、AllowUsers。restorecon -Rv ~/.ssh。sshd -t,再 reload,避免把自己锁在外面。ssh / ssh-keygen — 登录与密钥sshd — 服务端配置chmod / chown — 权限与属主restorecon — SELinux 上下文