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

Pas*_*day 9 security amazon-ec2 amazon-web-services

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

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

ssh ec2-user@myVirtualHost.compute-1.amazonaws.com -i ~/EC2key.pem -v
Run Code Online (Sandbox Code Playgroud)

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

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]
Run Code Online (Sandbox Code Playgroud)

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

Pas*_*day 7

我既高兴又谦虚地报告问题是我试图与不存在的用户一起使用ssh。我遵循的教程建议使用登录名,该登录名与相应的AMI中的用户名不匹配。亚马逊支持人员在仔细检查教程时提出了这一建议。

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

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