AWS更换服务器密钥对

最近遇到开发离职,所以涉及到更改服务器密钥。ubuntu

1.在aws后台生成并下载密钥,而后将密钥保存到本身电脑。服务器

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

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注释或者删除。code

4.而后你就能够利用新的密钥文件(.pem后缀文件)登陆服务器了
例如:ssh -i "test.pem" ubuntu@192.168.1.1orm

  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.
相关文章
相关标签/搜索