AWS Discussion Forum
EC2 key pair - Printable Version

+- AWS Discussion Forum (https://letstalkaws.com)
+-- Forum: Q & A (https://letstalkaws.com/forum-10.html)
+--- Forum: System Administration Help (https://letstalkaws.com/forum-25.html)
+--- Thread: EC2 key pair (/thread-79.html)



EC2 key pair - fborges5555 - 29-09-2022

Hi gurus.

I have an ec2 instance already with a Key-pair, is there a way I can have a second Key-pair for a user to use SSH tunnel to this ec2 that already exists?

Thanks gurus


RE: EC2 key pair - fzs - 29-09-2022

(29-09-2022, 12:33 AM)fborges5555 Wrote: Hi gurus.

I have an ec2 instance already with a Key-pair, is there a way I can have a second Key-pair for a user to use SSH tunnel to this ec2 that already exists?

Thanks gurus

Yes you can.

For each user account, the ssh key is stored in the folder ~/.ssh (i.e. /home/<user>/.ssh). The key itself is in a file called 'authorized_keys'.

You can generate a new key pair on your local machine with either the ssh-keygen command line utility or even an application like putty. Then upload the public key pair as 'authorized_keys'. Remember that this should be done under the respective user folder, not on root. After this, everytime a user attempts to connect via SSH, it should accept their ssh key for logging in. This is assuming that there is no configuration in the /etc/ssh/sshd_config file that explicitly denies a user from being able to login via ssh with key.

If you're trying to just add another keypair for the standard user like ec2-user or root, you just need to append the new key to the existing authorized_keys file in that user ssh folder.