虽然提供了PEM文件,但连接AWS EC2实例会要求输入密码

时间:2013-03-21 08:57:05

标签: security amazon-web-services amazon-ec2

我刚在AWS上创建了一个EC2实例。在此之前,我创建了我的密钥对,下载了私钥。

我现在正在尝试登录新创建的实例(使用正确的主机名,当然,为了安全起见,我在这里替换了)。我添加了-v开关来获取调试输出:

ssh ec2-user@myVirtualHost.compute-1.amazonaws.com -i ~/EC2key.pem -v

虽然我提供了密钥文件,但我被要求输入密码。以下是调试输出的摘录,可能显示出现了什么问题:

debug1: Host 'myVirtualHost.compute-1.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /home/myuser/.ssh/known_hosts:15
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,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/myuser/EC2key.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
ec2-user@myVirtualHost.compute-1.amazonaws.com's password:[asks for password here]

为什么在“读完PEM私钥后输入:输入RSA”后,结论是“可以继续的身份验证:公钥,密码”?

3 个答案:

答案 0 :(得分:5)

我很高兴和谦虚地报告问题是我试图与不存在的用户进行ssh。我所遵循的教程建议使用与相应AMI中的用户名不对应的登录名。这是亚马逊支持的建议,当他们仔细检查他们的教程时。

我不确定是否有办法从EC2管理控制台发现默认登录名。至少在属性中快速搜索正确的用户名并未显示任何匹配项。

现在我也可以在不通过-i选项提供密钥文件的情况下登录,因为我已经使用ssh-add命令将密钥添加到我的密钥环中。

答案 1 :(得分:1)

您是否尝试在密钥环中添加密码?

去扔这篇文章

http://aws.amazon.com/articles/1233

# vi /etc/ssh/sshd_config

找到该行 PasswordAuthentication yes

并将其更改为 PasswordAuthentication no

保存文件并重新启动sshd: # /etc/init.d/sshd restart

答案 2 :(得分:0)

嗯,就其失败的原因而言,这可能是客户端或服务器端。

客户端:确保您的.ssh目录是权限0700,EC2key.pem是0600。

服务器端:确保' PubkeyAuthentication'设置为“是”'在你的 sshd_config 中(如果你能够进入的话)。您也可以使用调试模式(-d标志)手动运行SSH服务以捕获其他潜在原因(同样,如果您有访问权限)。