Sunday 4 November 2018

How to create separate system user account in AWS EC2 instance



Login to the instance and switch to the root user:

[ec2-user@linuxcnf ~]$ sudo su -

Run the following command to add the new system user account to the system

[ec2-user@linuxcnf ~]$ sudo useradd User-Name

Run the following command to add the user to wheels group for root privileges:

[ec2-user@linuxcnf ~]$ sudo usermod -a -G wheel User-Name

Switch to the newly created user account

[ec2-user@linuxcnf ~]$ sudo su – User-Name
[User-Name@linuxcnf ~]$

Create a .ssh directory in the User-Name’s home directory and change the its permissions to 700

[User-Name@linuxcnf ~]$ mkdir .ssh
[User-Name@linuxcnf ~]$ chmod 700 .ssh

Go to the .ssh directory and create a file named authorized_keys and change the file permissions to 600

[User-Name@linuxcnf ~]$ touch .ssh/authorized_keys
[User-Name@linuxcnf ~]$ chmod 600 .ssh/authorized_keys

Now open the authorized_keys file and paste the public key pair into the file and save the changes. If Key pair is not available follow the tutorial How to Generate SSH Keys pairs using command line in Centos 7 and create a key pair.

  
[User-Name@linuxcnf ~]$ vi .ssh/authorized_keys

The user should now be able to log into the EC2 instance with newly create user User-Name using the key pair.

No comments:

Post a Comment