AWS更换密钥

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

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

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

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCMAS8mviirg23XvhyGzydp0VlP/fyfuhsHKMECZydc5ewytvTq0mqYTfjKBS++PeBpEL1Zx/ilEYCmgY6omTrIMtG8s1jf/lAk0l9++f2ldp/w2U86seARyRxVEePU7YCnbofqgtGJJDASDHNiEbshXQ6M49nUsE6tfETG3sFl+XDeva0lkNkssA4JDU+eivPRGma3XcBAXvsUsD8VkKQJvudrpJDSjjncdjYOVd2Wcrcj5Li8MmLvIkEX1pmqTT6O6oUfEtCdpVi4tCwTXV5ydU8UtjJDSGDFSJgbY9Unve4LgjgoWF677FdUpvVFD1NPoLH

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

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

  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.

参照:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#replacing-key-pair
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#retrieving-the-public-key

你可能感兴趣的:(linux)