The steps to create a user with the same rights as ec2-user are:

create the account

useradd NEWACCOUNT

set a password for the account

passwd NEWACCOUNT

add the account to the sudo group

usermod -aG sudo NEWACCOUNT

log in with the account

su – NEWACCOUT

create a .ssh directory

mkdir .ssh

log out of NEWACCOUNT

exit

now you are back in root, copy the authorized_keys file, and set security on .ssh

cp /home/ec2-user/.ssh/authorized_keys /home/NEWACCOUNT/.ssh/authorized_keys

chmod 700 /home/NEWACCOUNT/.ssh

Log all the way out of the system, and try and log in with the NEWACCOUNT.

Once logged in invoke sudo su to ensure it has the correct rights. You should get an error message.

The last step is to replace ec2-user with NEWACCOUNT in the file:

/etc/sudoers.d/cloud-init

The easiest way is with the nano editor, but there are many other editors in linux.

Advertisements