【问题标题】:Why can't I ssh into this EC2 instance?为什么我不能 ssh 进入这个 EC2 实例?
【发布时间】:2016-04-27 00:02:58
【问题描述】:

这个问题已经被问过很多次了(我今天已经阅读了很多),但我仍然看不出我在尝试 ssh 到 EC2 实例时做错了什么。这是我所做的:

这是一个 EC2 中型实例,运行 ubuntu Linux。 我创建了一个新的密钥对并下载了 rick_casey.pem 文件, 将其移至 ~/.ssh,然后

chmod 400 rick_casey.pem

然后将其添加到我的 ssh 身份中:

ssh-add rick_casey.pem

但是当我尝试连接时,会发生以下情况:

ssh -v -i "rick_casey.pem" ubuntu@ec2-54-237-54-42.compute-1..amazonaws.com
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /Users/rickcasey/.ssh/config
debug1: /Users/rickcasey/.ssh/config line 8: Applying options for *.amazonaws.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 53: Applying options for *
debug1: Connecting to ec2-54-237-54-42.compute-1.amazonaws.com [54.237.54.42] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file rick_casey.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file rick_casey.pem-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/rickcasey/.ssh/rick_casey.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/rickcasey/.ssh/rick_casey.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to ec2-54-237-54-42.compute-1.amazonaws.com:22 as 'ubuntu'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:Zu9shRhr3d+STyKTHKkhE2ZC1esSrALqNPGj3UtN8IA
Warning: Permanently added 'ec2-54-237-54-42.compute-1.amazonaws.com,54.237.54.42' (ECDSA) to the list of known hosts.
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: Offering RSA public key: rick_casey.pem
debug1: Authentications that can continue: publickey
debug1: Trying private key: rick_casey.pem
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/rickcasey/.ssh/rick_casey.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

在我看来可疑的是这行:

debug1: key_load_public: No such file or directory

有人知道这是什么意思吗?这是不是公钥有问题?当您生成 AWS 密钥对时,公钥是否不会自动添加到它应该在的 AWS 服务器中?

其他用户可以毫无问题地通过 ssh 登录到该服务器,所以我没有理由不能做同样的事情......但是有人对我应该尝试什么有建议吗?

谢谢, 瑞克

【问题讨论】:

  • 可以删除已知主机再试一次吗?
  • 让另一个用户登录并检查您的新密钥是否存在于服务器上的 authorized_keys 中。如果没有,请在此处添加。
  • “ubuntu”是正确的用户名吗?
  • 你的用户名是什么?使用它而不是 ubuntu
  • 我的实例中至少有一半是 Ubuntu,而且我一直不得不使用 ec2-user 作为登录名。

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


【解决方案1】:

当您生成 AWS 密钥对时,公钥不会自动添加到该 AWS 服务器应该在的位置吗?

当然不会,除非您使用该密钥启动 实例。您提到其他用户能够登录,这意味着这不是您使用此密钥启动的实例。

要在现有实例上使用新密钥,您必须将您的私钥的相应公钥附加到 /home/ubuntu/.ssh/authorized_keys(或“ec2-user”,或任何用户名应该是 - - Amazon Linux 使用“ec2-user”而 Ubuntu 使用“ubuntu”)...但是当然,在这种情况下,没有理由使用 EC2 控制台生成密钥...您可以通过以下方式完成相同的结果在本地生成私钥。

但是,由于您已经拥有密钥,您可以使用 ssh-keygen -y -f /path/to/your-private-key.pem 从私钥中提取公钥,并将其提供给您的管理员,管理员需要将其添加到服务器用户的 authorized_keys 文件中。

【讨论】:

    猜你喜欢
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多