EC2 Key Pair Change

后端 未结 5 706
轮回少年
轮回少年 2021-01-06 08:11

I have seen several questions and answers about changing the EC2 key pair for a running instance. However I am a complete AWS newbie at this point and I can easily stop the

相关标签:
5条回答
  • 2021-01-06 08:29

    You can create an AMI of your current instance and spin up a new instance with a different key pair using that AMI. You can then associate your elastic IP with the new instance. Is that what you're looking to do?

    0 讨论(0)
  • 2021-01-06 08:35

    No, you can't change the key pair for an instance using AWS management console. The only way to change the key is explained here: Change key pair for ec2 instance

    In a nutshell, SSH key is a file, created in the EC2 instance by AWS during setup. Once the file is there, AWS is not touching it. It's only you who can work with it.

    0 讨论(0)
  • 2021-01-06 08:37

    I agree with @yegor256 on the best method here to change your keys. You can also visually inspect the authorized_keys file to ensure that only the correct keys are listed--especially when using someone else's AMI. Just be sure the file has the correct permissions or you could lock yourself out accidentally.

    0 讨论(0)
  • 2021-01-06 08:41

    You are sort of out of luck with regards to changing the key pair associated with the instance. What you can do, though, is one of the following:

    • Create a new account with equivalent privileges to the one associated with your key pair, and generate a key pair for that account. Disable the account you wish to deprecate (the one associated with the existing key pair), and delete it from your key pair list. WARNING: if you do what I just wrote in the wrong order, you are out of luck.
    • This should work. Emphasis on "should." I believe you can create an AMI image from your existing machine. Then you can just recreate it and associate it with a new key pair, then terminating your old one.

    For future reference, best practice would be to have a common key file that is not accessible to everyone to create EC2 instances, then assign credentials for people to do work on them.

    0 讨论(0)
  • 2021-01-06 08:48

    Change key pair in AWS Ec2 instance.

    Sometimes it's necessary to change the private key for some security reason. We can able to change the private key or key pair while running the Ec2 instances.

    In the case of changing the private key pair, we need to enter the SSH using the below command.

    • Chmod 400 key.pem • Ssh user @ip-ikey.pem

    Example: ssh ubuntu@108.23.68.92-itest.pam

    Change the existing key pair

    ssh-keygen
    

    The created private key will be restored in /home/user/.ssh/id_rsa, and the public key will be stored in /home/user/.ssh/id_rsa.pub.
    Then copy the public key from id_rsa.pub file to /home/user/.ssh/authorized_ key file.

    The next step is to copy the private key which named as “id_rsa” in the file and then recreate the new file name it as (try. pem) in the local system.

    Connect to Ec2 instance by using the recently created private key.

    chmod 400 try.pem
    ssh  Ubuntu@ip –I try.pem
    

    Start your instance by using the private key. enter link description here

    0 讨论(0)
提交回复
热议问题