AWS-从AMI创建新实例,但是丢失了密钥? [英] AWS - Create new instance from AMI, but lost keys?

查看:347
本文介绍了AWS-从AMI创建新实例,但是丢失了密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个几周前创建的AMI.我想启动一个新的AWS EC2实例,并提供该AMI作为映像.问题是,我现在不能缩进那个盒子里.

I have an AMI that I created a few weeks ago. I want to launch a new AWS EC2 instance and provide that AMI as the image. Problem is, I can't ssh into that box now.

在启动新实例时,我尝试附加一个新的密钥对,但是好像盒子上SSH密钥的配置忽略了我的新附加的密钥对.

I have tried to attach a new key pair when launching the new instance, but it's as if the configuration of the SSH keys on the box is ignoring my newly attached key pair.

有没有办法解决这个问题?

Is there a way to overcome this issue?

我知道我的新密钥对有效,我已经在一个完全空白的新实例上对其进行了测试,并且可以正常使用SSH.

I know my new key pair works, I've tested it on a totally blank new instance and I can SSH in just fine.

任何帮助将不胜感激!

推荐答案

密钥对仅在首次引导磁盘时才复制到Amazon EC2实例.由于您已经从该磁盘(或用于创建映像的磁盘)启动,因此它将不会再次复制密钥对.

The keypair is only copied to the Amazon EC2 instance the first time that the disk is booted. Since you have already booted from that disk (or a disk from which the image was made), it will not copy the keypair again.

您需要将新的密钥对复制到/home/ec2-user/.ssh目录.可以通过将EBS卷附加到其他实例来完成此操作:

You will need to copy a new keypair to the /home/ec2-user/.ssh directory. This can be done by attaching the EBS volume to a different instance:

  • 停止实例(Instance 1)
  • 卸下EBS卷(记下设备标识符,例如/dev/xvda)
  • 将EBS卷附加到另一个Linux实例(Instance 2)
  • 编辑/home/edc2-user/.ssh/authorized_keys文件并插入所需的公共密钥
  • Instance 1卸下EBS卷,然后将其重新连接到Instance 2
  • 启动Instance 1并使用新的密钥对对其进行SSH
  • Stop the instance (Instance 1)
  • Detach the EBS volume (make a note of the device identifier, eg /dev/xvda)
  • Attach the EBS volume to another Linux instance (Instance 2)
  • Edit the /home/edc2-user/.ssh/authorized_keys file and insert your desired public key
  • Detach the EBS volume from Instance 1, re-attach it to Instance 2
  • Start Instance 1 and ssh to it using your new keypair

请参阅文档: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆