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 ec2-54-173-191-129.compute-1.amazonaws.com)
For example:
ssh -i "arunkg.pem" ec2-user@ec2-54-173-191-129.compute-1.amazonaws.com



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
hz2ItxCih+PnDSUaw+WNQn/mZphTk/a/gU8jEzoOWbkM4yxyb/wB96xbiFveSFJuOp/d6RJhJOI0iBXr
lsLnBItntckiJ7FbtxJMXLvvwJryDUilBMTjYtwB+QhYXUMOzce5Pjz5/i8SeJtjnV3iAoG/cQk+0FzZ
qaeJAAHco+CY/5WrUBkrHmFJr6HcXkvJdWPkYQS3xqC0+FmUZofz221CBt5IMucxXPkX4rWi+z7wB3Rb
BQoQzd8v7yeb7OzlPnWOyN0qFU0XA246RA8QFYiCNYwI3f05p6KLxEXAMPLE




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