连接AWS EC2实例要求输入密码,尽管提供了PEM文件



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

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

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]

为什么在"read PEM private key done: type RSA"之后,结论是"Authentications that can continue: publickey,password"?

我既高兴又谦卑地报告这个问题是我试图与不存在的用户ssh。我所遵循的教程建议使用与各自AMI中的用户名不对应的登录名。这是亚马逊支持人员在仔细检查他们的教程时建议的。

我不确定是否有一种方法可以从EC2管理控制台发现默认登录名。至少在属性中快速搜索正确的用户名没有找到任何匹配项。

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

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

客户端:确保您的.ssh目录是权限0700和EC2key。Pem为0600。

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

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

去扔这篇文章

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

# vi /etc/ssh/sshd_config

查找行PasswordAuthentication yes

并将其更改为PasswordAuthentication no

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

最新更新