AWS更换服务器密钥对

最近遇到开发离职,因此涉及到更改服务器密钥。

1.在aws后台生成并下载密钥,然后将密钥保存到自己电脑。

2.执行ssh-keygen -y,复制密钥路径,回车得到public key,例如

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe53pcjqP3maAhDFcvBS7O6V
hz2ItxCih+PnDSUaw+WNQn/mZphTk/a/gU8jEzoOWbkM4yxyb/wB96xbiFveSFJuOp/d6RJhJOI0iBXr
lsLnBItntckiJ7FbtxJMXLvvwJryDUilBMTjYtwB+QhYXUMOzce5Pjz5/i8SeJtjnV3iAoG/cQk+0FzZ
qaeJAAHco+CY/5WrUBkrHmFJr6HcXkvJdWPkYQS3xqC0+FmUZofz221CBt5IMucxXPkX4rWi+z7wB3Rb
BQoQzd8v7yeb7OzlPnWOyN0qFU0XA246RA8QFYiCNYwI3f05p6KLxEXAMPLE my-key-pair

3.利用以前的密钥登录服务器,将上面第二步的public key粘贴到~/.ssh/authorized_keys
或者相应登录用户的.ssh目录(我的是/home/ubuntu/.ssh/authorized_keys)
然后将旧的public key注释或者删除。

4.然后你就可以利用新的密钥文件(.pem后缀文件)登录服务器了
例如:ssh -i "test.pem" ubuntu@192.168.1.1

  1. Create a new key pair using AWS EC2 console or a third party tool.
  2. Retrieve the public key from new key pair.
  3. Connect to the instance using the existing private key.
  4. Using text editor to open .ssh/authorized_keys, paste the public key of new key pair into the authorized_keys file.
  5. (Optional) Delete the public key information of the original key pair in the authorized_keys file.
    原文作者:junfeng777
    原文地址: https://segmentfault.com/a/1190000012625684
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞