How to create new user account in EC2 instance | Arkit

By default whenever you log in to AWS EC2 Linux instance you have to use ec2-user or root or fedora those users come along with default Linux instance configuration. How Do I Add New user accounts with SSH Access to a Linux instance?

HowTo Add New User Accounts With SSH Access To a Linux Instance

Login to AWS console >> Launch new Linux EC2 Instance

Login to Linux instance using public IP address Or Public DNS address. Create new user using below command and also create SSH directory authorized key file to add public key content.

# sudo useradd aravi
# sudo su - aravi
# pwd
/home/aravi <<-- Ensure your in correct user home path before creating ssh directory and key file
# mkdir .ssh; chmod 700 .ssh;
# touch .ssh/authorized_keys
# chmod 600 .ssh/authorized_keys;

Now come back to your Linux server or windows machine from where you want to access AWS instance.

If it is Linux server generate SSH key pair using below commands

# ssh-keygen -t rsaGenerating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): Hit ENTER
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): Hit ENTER 
Enter same passphrase again: Hit ENTER 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:/UobsmzziNZ8uyklahsdfhasdkfg2x869bhhRO94 root@CentosServer.localdomain
The key's randomart image is:

# cat .ssh/id_rsa.pub

Copy this public key and paste it into AWS EC2 Linux instance authorized_keys file

In case your accessing AWS Linux instance from windows machine use Putty-Gen to generate key pair

ssh-key-pair

ssh-key-pair

as shown in above screenshot save both public key and private key

copy and paste Public Key file content into authorized_keys file

Accessing AWS Linux from outside world

From Linux

# ssh aravi@ec2-instance-public-ip

Windows machine

open putty >> type/paste public IP/Public DNS address of EC2 linux instance

Click +SSH > Auth > Browse and attach private key file

Click open

That’s it. AWS EC2 Add New User Accounts and disable default user

Related Articles

Thanks for your wonderful Support and Encouragement

ARK

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

Leave a Reply

Your email address will not be published.