多次尝试后 ssh 密钥权限被拒绝

ssh key permission denied after severral attempt

我多次访问服务器。我可以完美地连接。今天晚上我想再次连接它给我一个错误。

-> % ssh ubuntu@pkp-alm.lib.sfu.ca -v                          
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to pkp-alm.lib.sfu.ca [52.4.177.245] port 22.
debug1: Connection established.
debug1: identity file /home/guinsly/.ssh/id_rsa type 1
debug1: identity file /home/guinsly/.ssh/id_rsa-cert type -1
debug1: identity file /home/guinsly/.ssh/id_dsa type -1
debug1: identity file /home/guinsly/.ssh/id_dsa-cert type -1
debug1: identity file /home/guinsly/.ssh/id_ecdsa type -1
debug1: identity file /home/guinsly/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/guinsly/.ssh/id_ed25519 type -1
debug1: identity file /home/guinsly/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA c6:7c:32:1c:70:96:6e:ea:c0:84:96:79:3a:6c:06:bb
debug1: Host 'pkp-alm.lib.sfu.ca' is known and matches the ECDSA host key.
debug1: Found key in /home/guinsly/.ssh/known_hosts:21
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/guinsly/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: guinslym@gmail.com
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: guinsly@guinsly-ThinkPad-L430
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: guinslym@gmail.com
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/guinsly/.ssh/id_dsa
debug1: Trying private key: /home/guinsly/.ssh/id_ecdsa
debug1: Trying private key: /home/guinsly/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

我的 public 密钥被命名为 lagotto_rsa.pub,这是默认情况下应该使用的密钥,但现在它似乎找不到 public 密钥。

ssh -i ~/.ssh/lagotto_rsa.pub ubuntu@pkp-alm.lib.sfu.ca -v

也给了我Permission denied (publickey).

-> % ssh -i ~/.ssh/lagotto_rsa.pub ubuntu@pkp-alm.lib.sfu.ca -v
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to pkp-alm.lib.sfu.ca [52.4.177.245] port 22.
debug1: Connection established.
debug1: identity file /home/guinsly/.ssh/lagotto_rsa.pub type 1
debug1: identity file /home/guinsly/.ssh/lagotto_rsa.pub-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA c6:7c:32:1c:70:96:6e:ea:c0:84:96:79:3a:6c:06:bb
debug1: Host 'pkp-alm.lib.sfu.ca' is known and matches the ECDSA host key.
debug1: Found key in /home/guinsly/.ssh/known_hosts:21
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/guinsly/.ssh/lagotto_rsa.pub
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: guinslym@gmail.com
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: guinsly@guinsly-ThinkPad-L430
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: guinsly@guinsly-ThinkPad-L430
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

我也用私钥试过了。我想知道我的本地机器发生了什么变化,我无法再访问远程

不是你的遥控器有问题,而是你的服务器出了问题。仅当您更改了后端权限时才会发生此错误。这是一个真正令人讨厌的错误,我只能解决它,因为我的站点托管在数字海洋上,并且它们为您提供控制台访问权限。所以只有这样才有可能。从客户端您无能为力。如果可以的话,我曾在 ubuntu 上问过一个关于此的问题,请检查 link。否则让我知道

如果您可以通过任何其他方式连接到您的服务器,请检查 ~/.ssh/ 文件夹和 ~/ssh/authorized_keys 文件的权限。它们应该分别设置为 700600

您还可以检查 /var/log/auth.log 文件以查看尝试登录时发生的情况。如果您的系统有 systemd,您可以使用 sudo journalctl -u sshdsudo journalctl.

获取更多信息