How to add new user AWS EC2 instance and add .PPK file to allow access

AWS provides us a User with access key during initial setup, But in some case, we required another user with limited access only. We can't share sudoers user with anyone. In this blog, I will explain how to add new user and setup access key for remote access.

Prerequisites -

  • One EC2 Linux instance -    I am using Ubuntu 16.04 LTS
  • A user with Sudo access -   AWS default user Ubuntu
 Step 1- Add a new user:
In order to add a new user, log in to your EC2 instance using SSH PuTTY connection.
$ sudo adduser linux
 
 Step 2- Create .SSH folder and authorized_keys with correct permission.
Go to the home directory of the newly added user.
$ cd /home/linux/
Create a new directory with name .SSH
$ mkdir .ssh
Change ownership and permission.
$ chown -R linux:linux .ssh/ && chmod 700 .ssh/
 Go to SSH directory
$ cd .ssh/
Create file authorized_keys
$ touch authorized_keys
Change ownership and set permission
$ chown -R linux:linux authorized_keys && chmod 600 authorized_keys
 Step 3- Generate Public and Private Access key
To generate Public and Private Access key, I am using PuTTygen. Open PuTTygen and click on Generate. and during the process keep moving the cursor over the bank area to complete the process.
After Successful of key generation. Save the Private key somewhere in your PC. that will be used to make the connection with EC2 for new User Linux.
Step 4- Save the Private Key
In order to save Private key, choose Save private key buttion on the PuTTYgen windows. 
At next screen save the Private file with name Linux.PPK
Step 5- Copy Public key and add to Authorized_key file at EC2 instance inside Linux user.
Select all and copy public keys as in below screenshot.
Now Go to EC2 instance and paste copied public key in the file name authorized_key. Open file in VIM editor
$ vi authorized_keys
Paste public keys 
Save and Exit from the file.
Now you are ready to connect your EC2 instance using newly added user Linux.
Step 6-  Test SSH connection using the Private key.
Open PuTTY software and enter server IP address and in the SSH auth section browse and add Private key file.
Connect PuTTY and enter user Linux when asked.
You have successfully connected with newly added user Linux.

!!Cheers!!

1 comment: