Sunday, 15 July 2018

How to create a new user to EC2 Instance in AWS?

How to create a new user to EC2 Instance in AWS?

Step 1: Login to SSH
Login to Ec2 instance using public DNS (like
For example:
ssh -i "arunkg.pem"

Step 2: Use the following adduser command to add the newuser account to the system (with an entry in the /etc/passwd file).
sudo adduser newuser

Step 3:Switch to the new account so that newly created files have the proper ownership.
sudo su - newuser

Step 4 Create a folder and set the permission
mkdir .ssh
chmod 700 .ssh
cd .ssh

Step 5: Create a file named authorized_keys in the .ssh directory and change its file permissions to 600 (only the owner can read or write to the file).
touch authorized_keys
chmod 600 authorized_keys

Step 6: Open the authorized_keys and write public key in this.
vi authorized_keys

Paste the public key for your key pair into the file and save the changes.
For example:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe53pcjqP3maAhDFcvBS7O6V

Question: How to remove a user?
sudo userdel -r newuser