Add new users to an Amazon EC2 Ubuntu instance and allow SSH access

In many cases, we may need to create a user in the Amazon EC2 instance and provide SSH access. When we create an EC2 instance we get a .pem file for accessing the instance. That file allows SSH access to that instance. But if we want to add another user and allow SSH access we can do that too.

Following are the steps to create a user in Amazon EC2 Ubuntu instance with SSH access:

Add a new user

First of all create a user called joe under Ubuntu group.

$ sudo adduser joe ubuntu

Switch the terminal session

Switch the terminal session with the new user account

$ sudo su joe

Create .ssh directory

Create a directory named .ssh in the home folder:

$ mkdir .ssh

Give permission

Give permission to the .ssh folder

$ chmod 700 .ssh

Create authorized_keys file

Create authorized_keys file inside .ssh directory

$ touch authorized_keys

Add user’s public key

Add the public key id_rsa.pub to the authorized_keys file

$ vi authorized_keys

Try the SSH

Try the SSH from user’s machine like below:

$ ssh joe@ec2-public-ip.eu-west-1.compute.amazonaws.com

Source:
Add new user ec2 ubuntu
SSH keys on ec2