【问题标题】:generated new ssh key on aws instance and now i'm locked out (can't ssh in)在 aws 实例上生成了新的 ssh 密钥,现在我被锁定了(无法 ssh 进入)
【发布时间】:2014-06-17 10:16:51
【问题描述】:

我在 aws 实例上有一个 ssh 密钥(我们称之为密钥 a);但是,它不允许我访问我的 github 帐户,所以我生成了一个新的 ssh 密钥(密钥 b)。好事是我能够访问 github,但坏事是我现在无法通过 ssh 访问我的 aws 实例。

知道我能做什么吗?我尝试更改 pem 文件的权限无济于事。我在aws上远程运行ubuntu 12.04,在本地运行windows机器。

附加信息:当我创建密钥 b 并将其命名为 rsa_id.pub 时,我并没有有意或明确地覆盖密钥 a。我尝试了两种语法,ssh(我的默认)和 ssh -i xxx.pem ubuntu@ec2-xxx-xx-xxx-x.compute-1.amazonaws.com。这些语法都不起作用。

OpenSSH_6.4, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /home/xx/.ssh/config
debug1: /home/xx/.ssh/config line 1: Applying options for awshost1
debug1: Connecting to ec2-xx-xxx-xxx-xx.us-west-2.compute.amazonaws.com [54.201.134.83] port 22.
debug1: Connection established.
debug1: identity file /home/xx/.ssh/xx.pem type -1
debug1: identity file /home/xx/.ssh/xx.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH_5*
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: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
debug1: Host 'ec2-xx-xxx-xxx-xx.us-west-2.compute.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /home/xx/.ssh/known_hosts:1
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
debug1: Next authentication method: publickey
debug1: Trying private key: /home/xx/.ssh/xx.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).

【问题讨论】:

  • 一经设置,始终在 S3 上创建服务器快照。这样一来,您就可以从 AWS 数据中心的硬件故障到更改 SSH 密钥等任何事情中恢复。

标签: amazon-web-services ssh


【解决方案1】:

如果您的实例由 EBS 支持 (and it should be),则不会丢失所有内容。您可以将实例移动到机器上并在此过程中设置新密钥:

http://blog.celingest.com/en/2013/11/14/replace-lost-keypair-ec2-instance/

【讨论】:

    【解决方案2】:

    这里缺少两个重要的信息:

    • 您是创建了新密钥,还是覆盖了现有密钥(在本地计算机上)

    • 您尝试 ssh 的具体情况如何,也就是说,确切的 ssh 语法是什么?

    假设您生成了一个新密钥来访问您的 github 帐户,这应该不会影响您的 AWS 实例的现有密钥对。你应该按照

    的方式运行一些东西
    ssh -i /path/to/key.pem ubuntu@your-public-dns-name 
    

    此外,您应该确保您的密钥文件具有适当的权限。

    【讨论】:

    • 我已将附加信息添加到原始帖子中。我已确保权限正确,但仍然没有成功。
    猜你喜欢
    • 2023-03-22
    • 2021-12-08
    • 2011-09-01
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 2012-07-29
    相关资源
    最近更新 更多