如何在AWS管理控制台中更改ec2实例的密钥对?我可以停止实例,我可以创建新的密钥对,但我没有看到任何链接来修改实例的密钥对。
当前回答
我认为最简单的方法是:
创建现有实例的AMI映像。 使用AMI映像(由步骤1创建)和新的密钥对启动新的EC2实例。 使用新密钥登录到新的EC2实例。
其他回答
我尝试了这种方法,过了一段时间后,我能够让它工作。缺乏实际的命令让它很困难,但我想出了办法。然而,不久之后发现并测试了更简单的方法:
将实例保存为AMI(不管是否重启,我建议重启)。这只有在EBS支持的情况下才能奏效。 然后,只需从这个AMI启动一个实例并分配新的Keyfile。 将弹性IP(如果适用)转移到新实例,就完成了。
这个答案是有用的情况下,您不再有SSH访问现有的服务器(即您丢失了您的私钥)。
如果您仍然拥有SSH访问权限,请使用下面的答案之一。
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#replacing-lost-key-pair
以下是我所做的,感谢Eric Hammond的博客文章:
停止正在运行的EC2实例 分离它的/dev/xvda1卷(我们称它为卷A)—请参见这里 开始新的t1。microec2实例,使用我的新密钥对。确保在相同的子网中创建它,否则将不得不终止实例并重新创建它。-请看这里 将卷A挂载到新的微实例,如/dev/xvdf(或/dev/sdf) SSH到新的微实例,将卷A挂载到/mnt/tmp
$ sudo mkdir /mnt/tmp; sudo mount /dev/xvdf1 /mnt/tmp
~ /副本。Ssh /authorized_keys到/mnt/tmp/home/ubuntu/.ssh/authorized_keys 注销 终止微实例 从它分离卷A 将卷A挂回主实例为/dev/xvda 启动主实例 像以前一样登录,使用新的.pem文件
就是这样。
您有几个选项可以替换EC2实例的密钥。
您可以在.ssh/authorized_keys文件中手动替换密钥。但是,这需要您实际访问实例或卷(如果未加密)。 您可以使用AWS系统管理器。这需要安装代理。
由于第一个选项可以很容易地在答案中或在您选择的搜索引擎中找到,所以我想重点介绍系统管理器。
打开服务系统管理器 单击左侧的Automation。 单击执行自动化 选择AWSSupport-TroubleshootSSH(通常在最后一页)
您可以在AWS官方文档中找到更多信息
来自AWS EC2支持的指令:
Change pem login go to your EC2 Console Under NETWORK & SECURITY, click on Key Pair Click on Create Key Pair Give your new key pair a name, save the .pem file. The name of the key pair will be used to connect to your instance Create SSH connection to your instance and keep it open in PuttyGen, click "Load" to load your .pem file Keep the SSH-2 RSA radio button checked. Click on "Save private key" You'll get pop-up window warning, click "Yes” click on "Save public key" as well, so to generate the public key. This is the public key that we're going to copy across to your current instance Save the public key with the new key pair name and with the extension .pub Open the public key content in a notepad copy the content below "Comment: "imported-openssh-key" and before "---- END SSH2 PUBLIC KEY ---- Note - you need to copy the content as one line - delete all new lines on your connected instance, open your authorized_keys file using the tool vi. Run the following command: vi .ssh/authorized_keys you should see the original public key in the file also move your cursor on the file to the end of your first public key content :type "i" for insert on the new line, type "ssh-rsa" and add a space before you paste the content of the public key , space, and the name of the .pem file (without the .pem) Note - you should get a line with the same format as the previous line press the Esc key, and then type :wq!
这将保存更新后的authorized_keys文件
现在尝试使用新的密钥pai打开一个新的SSH会话到您的实例
当您确认能够使用新的密钥对SSH进入实例时,您可以vi . SSH /authorized_key并删除旧的密钥。
对Shaggie评论的回答:
如果您无法连接到实例(例如密钥损坏),请使用AWS控制台分离卷(http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html)并将其重新连接到工作实例,然后更改卷上的密钥并将其重新连接到前一个实例。
替代解决方案。如果你有唯一的访问服务器。在这种情况下,不要从AWS控制台删除pem文件。只需删除pem访问密钥从sudo纳米~/。Ssh / authized_keys,并添加系统公共Ssh密钥。现在您可以访问ssh user@i.p
推荐文章
- 如何查看所有地区所有正在运行的Amazon EC2实例?
- 如何从命令行使用多个AWS帐户?
- 如何搜索亚马逊s3桶?
- 通过SSH使用Eclipse完成远程项目
- 如何强制从另一个SSH会话分离屏幕?
- com.jcraft.jsch.JSchException: UnknownHostKey
- 如何在Python中scp ?
- 在SSH会话中查找客户端的IP地址
- 拒绝访问;您需要(至少一个)SUPER特权来执行此操作
- 我如何使用通配符“cp”一组文件与AWS CLI
- 自定义SSH端口上的Git
- 我如何获得亚马逊的AWS_ACCESS_KEY_ID ?
- 如何使所有对象在AWS S3桶公共默认?
- Git显示“警告:永久添加到已知主机列表”
- 为什么git在Windows下记不住我的密码