‘ssh localhost’ 显示‘权限被拒绝(公钥)’。

‘ssh localhost’ 显示‘权限被拒绝(公钥)’。

我将提到我尝试过的许多方法,并提供一些诊断。我将不胜感激任何有关如何调试此问题的线索:

me@myubuntu:~/.ssh$ ssh localhost
Permission denied (publickey).

之前我跑过

sudo ufw allow ssh/tcp

在我的路由器上设置端口 22 的端口转发,并验证该端口已打开这里(但可能没有必要——当我 ssh 到自己时,ssh 是否会到达路由器?)。

在我的 home/.ssh 目录中,我执行了该操作cat id_rsa.pub >> authorized_keys并使用 设置了权限chmod 600 authorized_keys

运行ssh -v localhost会产生很多输出,这里是我认为问题发生的最后几行:

debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /home/me/.ssh/known_hosts:3
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/me/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: me@myubuntu
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/me/.ssh/id_dsa
debug1: Trying private key: /home/me/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

我成功通过 ssh 连接到我的 bitbucket 存储库,所以我认为这意味着我的 id_rsa 密钥集有效且具有正确的权限。

更新 1:

> ~/.ssh$ ls -l ~/.ssh/authorized_keys
-rw------- 1 me me 747 Oct 25 08:27 /home/me/.ssh/authorized_keys

(看起来不错)

更新 2:

~/.ssh$ ls -ld ~/.ssh
drwx------ 2 me me 4096 Oct 25 08:27 /home/me/.ssh

(看起来不错)

更新 3:/var/log/auth.log我运行后最后几行ssh localhost

Oct 25 09:49:47 me-myubuntu sshd[16442]: Connection from 127.0.0.1 port 36944
Oct 25 09:49:47 me-myubuntu sshd[16442]: User me from localhost not allowed because not listed in AllowUsers
Oct 25 09:49:47 me-myubuntu sshd[16442]: input_userauth_request: invalid user me [preauth]
Oct 25 09:49:47 me-myubuntu sshd[16442]: Connection closed by 127.0.0.1 [preauth]

看看这个!我之前弄乱了 sshd_config 文件,忘记正确指定我的 AllowUsers 选项。

解决方案:在行localhost中包含AllowUserssudo gedit /etc/ssh/sshd_config

答案1

请检查/var/log/auth.log连接过程中可能出现的错误。此行

10 月 25 日 09:49:47 me-myubuntu sshd[16442]: 不允许使用 localhost 的用户 me,因为未在 AllowUsers 中列出

指出了问题所在。

相关内容