First Way :
Follow the below steps
Follow the below steps
Instruction from AWS EC2 support:
- 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!
this will save the updated authorized_keys file
now try open a new SSH session to your instance using your new key pai
When you've confirmed you're able to SSH into the instance using the new key pair, u can vi .ssh/authorized_key and delete the old key.
Second Ways
- Stop the running EC2 instance
- Detach its
/dev/xvda1
volume (let's call it volume A) - see here - Start new t1.micro EC2 instance, using my new key pair. Make sure you create it in the same subnet, otherwise you will have to terminate the instance and create it again. - see here
- Attach volume A to the new micro instance, as
/dev/xvdf
(or/dev/sdf
) - SSH to the new micro instance and mount volume A to
/mnt/tmp
$ sudo mount /dev/xvdf1 /mnt/tmp - Copy
~/.ssh/authorized_keys
to/mnt/tmp/home/ubuntu/.ssh/authorized_keys
- Logout
- Terminate micro instance
- Detach volume A from it
- Attach volume A back to the main instance as
/dev/xvda
- Start the main instance
- Login as before, using your new
.pem
file
That's it.
0 comments:
Post a Comment