【发布时间】:2015-11-09 16:13:22
【问题描述】:
当我尝试 ssh 到我的 AWS 实例时,我收到“权限被拒绝(公钥)”。
搜索此问题的解决方法通常是确保 .pem 密钥具有“chmod 600”的正确权限。另一种解决方案是以 root 或 ec2-user 身份登录。我都试过了。
独特之处在于我可以使用相同的密钥并登录到较旧的 AWS 实例,然后尝试记录我新创建的实例并获得权限被拒绝错误。在 AWS 中,两者都显示使用相同的“密钥对名称”。因此,如果它们在 AWS 中的密钥对是相同的,并且密钥在一个盒子上有效,那么为什么另一个盒子上会出现问题?
失败的盒子(同一个键)
$ ssh -v -i .ssh/aws_match.pem root@52.23.xxx.xxx
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 52.23.xxx.xxx [52.23.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file .ssh/aws_match.pem type -1
debug1: identity file .ssh/aws_match.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH*
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: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 5c:5b:54:a6:50:ec:3b:ba:aa:4f:00:2a:90:b3:a9:9b
debug1: Host '52.23.195.151' is known and matches the RSA host key.
debug1: Found key in /Users/pumphreyjj/.ssh/known_hosts:12
debug1: ssh_rsa_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: Trying private key: .ssh/aws_match.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
有效的盒子(相同的键)
$ ssh -v -i .ssh/aws_match.pem root@54.84.xx.xxx
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 54.84.xx.xxx [54.84.xx.xxx] port 22.
debug1: Connection established.
debug1: identity file .ssh/aws_match.pem type -1
debug1: identity file .ssh/aws_match.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA f0:94:93:93:fa:1d:37:ec:6d:0a:22:78:2e:9c:d1:13
debug1: Host '54.84.81.152' is known and matches the RSA host key.
debug1: Found key in /Users/pumphreyjj/.ssh/known_hosts:3
debug1: ssh_rsa_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,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: .ssh/aws_match.pem
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to 54.84.xx.xxx ([54.84.xx.xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Mon Nov 9 10:43:36 2015 from 128.231.xxx.xxx
我看到的唯一区别是 OpenSSH 版本,但它是由 AWS 安装的。我还没有换过盒子。
【问题讨论】:
-
无法从此日志中调查它。您应该检查服务器端的日志,您将在其中找到更多详细信息。两台机器上可能会有不同的配置。
-
您使用的是哪个 AMI?亚马逊 Linux、Ubuntu、...?
标签: amazon-web-services ssh amazon-s3 amazon-ec2