I'm using Amazon Linux AMI.

When you create EC2 instance, by default the username is ec2-user.

I want to create another user (lets say user1) with the same privileges as ec2-user, and I want to delete ec2-user. Is it safe to delete the ec2-user?

Can you provide me linux commands how to do this please?

Sorry I'm noob when it comes to linux commands.

  • 1
    What is your motivation for removing the ec2-user user? "Is it possible" and "is it a good idea" may be two very different questions. Jan 19, 2016 at 22:00

5 Answers 5


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.

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.


On AWS, Instances are configured at launch using CloudInit. For Amazon Linux AMI, this is information is stored under /etc/cloud/cloud.cfg.d/00_defaults.cfg section system_info.

So, imho, the easiest solution to achieve what you want is to give the following User Data when launching your instance:

    name: user1

NB. This might not work exactly the same on different distributions where CloudInit's version differs.

Useful links:


Yes you can delete the default AWS ec-user. You can add a new user and access the EC2 Instance. But when you initially create an Instance at same time an SSH PUB/PRI key pair is also generated corresponding to ec2-user. So you have to first generate a new key pair in order to access EC-2 instance with new user.

  ****user add -----> useradd username**
  **user delete --> userdel username**** 

  but defaults user no need to delete , u can just change password 
  **password change - passwd username** 

far ubuntu

   ****user add -----> useradd -m username**
   **user delete --> userdel username**** 

Totally wrong and misguiding concept of deleting ec2-user whole AWS cloud features monitoring and other event based things become corrupted and of no use? Did you know about this consiquences or you need to do research on this still?


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .