The steps to create a user with the same rights as ec2-user are:
- create the account
- set a password for the account
- add the account to the sudo group
- usermod -aG sudo NEWACCOUNT
- log in with the account
- create a .ssh directory
- log out of NEWACCOUNT
- 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.
If this works, then you have a new account with the same priviledges as the ec2-user (and you have also removed ec2-user from the ability to become root) and can safely delete (or ignore) that account.