使用 SSH 密钥对访问 EC2 实例时出现问题

使用 SSH 密钥对访问 EC2 实例时出现问题

刚刚设置了一个新的 EC2 实例,下载了 pem 文件,但目前无法进入框。我正在使用命令...

$ ssh -i .ssh/key.pem ubuntu@ec2-176-34-183-***.eu-west-1.compute.amazonaws.com

...并要求输入密码。但我生成密钥对时没有指定密码!为什么会发生这种情况?

无论如何,我仔细研究了一下,找到了如何从密钥中删除密码:

$ openssl rsa -in key.pem -out key-nopass.pem

虽然密码确实被删除了,但仍然没有什么惊喜。这是我的详细输出:

OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /home/bob/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to ec2-176-34-183-***.eu-west-1.compute.amazonaws.com [176.34.183.***] port 22.
debug1: Connection established.
debug1: identity file key-nopass.pem type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debian-    3ubuntu7
debug1: match: OpenSSH_5.3p1 Debian-3ubuntu7 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu7
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: Host 'ec2-176-34-183-***.eu-west-1.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /home/bob/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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: key-nopass.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).

顺便说一下,pem 文件权限设置为 600。为什么我无法登录?

答案1

这里可能发生了一些事情。首先,您似乎正在尝试登录 ubuntu 用户。您确定该用户存在并且该密钥对与该用户相关联吗?我会尝试以 root 身份登录,看看是否可行。

另一种可能是你的私钥错误。你是直接下载的还是通过复制/粘贴创建的?如果是后者,那么你可能没有正确粘贴。

权限正确,因此一定是上述情况之一。私钥不在您尝试登录的 authorized_keys 中,或者您拥有错误的/损坏的密钥。

相关内容