如何在AWS管理控制台中更改ec2实例的密钥对?我可以停止实例,我可以创建新的密钥对,但我没有看到任何链接来修改实例的密钥对。
当前回答
谢谢你们的建议。当我需要休息钥匙对时,我一定会把它们记在心里。 然而,出于效率和懒惰的考虑,我想出了另一个办法:
创建新的密钥对并下载凭证 右键单击实例>创建AMI一旦完成 终止实例(或者只是停止它,直到您确定可以从新的闪亮AMI创建另一个实例) 从刚才创建的AMI启动一个新的EC2实例,并指定在上面步骤(1)中创建的新密钥对。
希望这能对你有用,为你节省一些时间,并尽量减少你从这样的东西得到的白发数量:)
其他回答
来自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
如果有人在这里,因为他们不能访问EC2实例,因为他们没有密钥对,但他们有IAM访问,你可以运行以下命令,允许临时访问(60秒)你的EC2实例使用你已经拥有的密钥,只要你知道用户名(通常是'ubuntu' ubuntu实例或' EC2 -user'亚马逊linux实例):
aws ec2-instance-connect send-ssh-public-key --region ${your-aws-region} --instance-id ${your-instance-id} --availability-zone ${your-instance-az} --instance-os-user ${username} --ssh-public-key file://path/to/public/key
(如果您的~/。Aws /凭据文件,您还可以通过在此命令中添加'——profile your-profile'标志来指定)
如果成功,输出将如下所示:
{
"RequestId": "3537268d-c161-41bb-a4ac-977b79b2bdc0",
"Success": true
}
然后你有60秒的时间用那把钥匙登录。
步骤:
创建新密钥,例如使用AWS控制台,PuTTY密钥生成器,或ssh-keygen 停止实例 设置实例用户数据以将公钥推送到服务器 启动实例
#cloud-config
cloud_final_modules:
- [once]
bootcmd:
- echo 'ssh-rsa AAAAB3Nz...' > /home/USERNAME/.ssh/authorized_keys
其中USERNAME是机器的预期用户名。可以从AWS获得默认用户名列表。
来自AWS的分步说明
这是为他们谁有两个不同的pem文件,并出于任何安全目的想要丢弃其中一个。假设我们想要丢弃1。pem
连接到服务器2,从~/.ssh/authorized_keys中复制ssh密钥 在另一个终端上连接服务器1,并将密钥粘贴到~/.ssh/authorized_keys中。现在您将有两个公共ssh密钥 现在,为了增强自信心,尝试使用2.pem连接服务器1。您将能够将服务器1与这两个1连接。Pem和2.pem 现在,注释1。Pem SSH,使用SSH -i连接。pem user@server1
推荐文章
- 亚马逊ECS和亚马逊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模块?