How do I add new user accounts with SSH access to my Amazon EC2 Linux instance?

1.    Connect to the EC2 Linux instance that you plan to add user accounts to.

2.    Run the following command

sudo adduser <new_user>

3.   Switch context to new user account

sudo su - <new_user>

4. Create .ssh directory

mkdir .ssh

5. Limit access to the .ssh directory

chmod 700 .ssh

6. Create the file ‘authorized_keys’ in the .ssh directory:

touch .ssh/authorized_keys

7. Change permission to authorized_keys

chmod 600 .ssh/authorized_keys

8. Run the following command  to generate public key

ssh-keygen -y

enter location of .PEM key-pair

9. Copy output public to key to  .ssh/authorized_keys

10. Verify that you can use SSH to connect to your instance.

ssh -i /path/<new_keypair>.pem <new_user>@public_dns_name_of_EC2_Linux_instance

  •  
  •  
  •  
  •  

Viet Luu has written 318 articles

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

We are thankful for your never ending support.

Leave a Reply