如何在AWS管理控制台中更改ec2实例的密钥对?我可以停止实例,我可以创建新的密钥对,但我没有看到任何链接来修改实例的密钥对。
当前回答
如果您无法登录VM并删除了ssh密钥,您也可以使用以下步骤更改ec2的密钥对。 一步一步来 1)停止你的ec2实例。 2)对虚拟机和存储进行快照。 3)创建一个新的虚拟机,同时创建它选择您的快照,并从您的快照创建虚拟机。 4)在创建虚拟机时下载您的密码对。 5)一旦你的虚拟机UP,你可以ssh一个新的密钥对,你的数据也会回来。
其他回答
只有当您可以访问想要更改/添加密钥的实例时,这才有效。 您可以创建新的密钥对。或者,如果您已经拥有密钥对,那么您可以将新密钥对的公钥粘贴到实例上的authorized_keys文件中。
vim . ssh / authorized_keys
现在您可以使用该对的私钥并登录。
希望这能有所帮助。
来自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)并将其重新连接到工作实例,然后更改卷上的密钥并将其重新连接到前一个实例。
最简单的解决方法是复制的内容
~/.ssh/id_rsa.pub
到您的AWS实例的authorized_keys at
~/.ssh/authorized_keys
这将允许您ssh进入EC2实例,而无需为ssh命令指定pem文件。测试连接后,可以删除所有其他键。
如果你需要创建一个新的密钥来与其他人共享,你可以通过:
ssh-keygen -t rsa
这将创建私钥。Pem文件,你可以通过以下方式获取该文件的公钥:
ssh-keygen -f private_key.pem -y > public_key.pub
任何拥有private_key的人。Pem能够连接到
ssh user@host.com -i private_key.pem
我的问题是,我尝试使用IP而不是公共DNS。然后我尝试了公共DNS和它的解决
我认为最简单的方法是:
创建现有实例的AMI映像。 使用AMI映像(由步骤1创建)和新的密钥对启动新的EC2实例。 使用新密钥登录到新的EC2实例。
推荐文章
- 运行ssh后立即执行命令
- 我如何知道我在S3桶中存储了多少对象?
- S3 Bucket操作不应用于任何资源
- 将AWS凭证传递给Docker容器的最佳方法是什么?
- 当权限为S3时,AccessDenied for ListObjects for S3 bucket:*
- 电子邮件地址未验证(AWS SES)
- ssh -L转发多个端口
- 使用Boto3将S3对象作为字符串打开
- 从PKCS12文件中提取公钥/私钥,供以后在SSH-PK-Authentication中使用
- 在python shell中按方向键时看到转义字符
- 如何忽略ansible SSH的真实性检查?
- 如何移除SSH密钥?
- AWS VPC - Internet网关vs. NAT
- 如何在AWS Lambda中加载npm模块?
- 亚马逊S3 -如何修复“我们计算的请求签名与签名不匹配”错误?