Managing User Accounts on Your Linux Instance
Each Linux instance type launches with a default Linux system user account.
For Amazon Linux, the user name is ec2-user.
For RHEL, the user name is ec2-user or root.
For Ubuntu, the user name is ubuntu or root.
For Centos, the user name is centos.
For Fedora, the user name is ec2-user.
For SUSE, the user name is ec2-user or root.
Otherwise, if ec2-user and root don't work, check with your AMI provider.
Note
Linux system users should not be confused with AWS Identity and Access Management (IAM) users. For more information, see IAM Users and Groups in the IAM User Guide.
Using the default user account is adequate for many applications, but you may choose
to add user accounts so that individuals can have their own files and workspaces.
Creating user accounts for new users is much more secure than granting multiple
(possibly inexperienced) users access to the ec2-user account, since
that account can cause a lot of damage to a system when used improperly.
To add a new user to the system
Effectively adding users to a Linux instance involves two basic operations: adding the user to the system, and providing that user with a way to log in remotely.
-
To add a new user to the system, use the adduser command followed by any relevant options and the name of the user you wish to create.
Important
If you are adding a user to an Ubuntu system, you should add the
--disabled-passwordoption to avoid adding a password to the account.
This command adds theCopy[ec2-user ~]$sudo addusernewusernewuseraccount to the system (with an entry in the/etc/passwdfile), creates anewusergroup, and creates a home directory for the account in/home/newuser. -
To provide remote access to this account, you must create a
.sshdirectory in thenewuserhome directory and create a file within it named "authorized_keys" that contains a public key.-
Switch to the new account so that newly created files have the proper ownership.
Note that the prompt now saysCopy[ec2-user ~]$sudo su -[newuser ~]$newusernewuserinstead ofec2-user; you have switched the shell session to the new account. -
Create a
.sshdirectory for theauthorized_keysfile.Copy[newuser ~]$mkdir .ssh -
Change the file permissions of the
.sshdirectory to700(this means only the file owner can read, write, or open the directory).Important
This step is very important; without these exact file permissions, you will not be able to log into this account using SSH.
Copy[newuser ~]$chmod 700 .ssh -
Create a file named "
authorized_keys" in the.sshdirectory.Copy[newuser ~]$touch .ssh/authorized_keys -
Change the file permissions of the
authorized_keysfile to600(this means only the file owner can read or write to the file).Important
This step is very important; without these exact file permissions, you will not be able to log into this account using SSH.
Copy[newuser ~]$chmod 600 .ssh/authorized_keys -
Edit the
authorized_keysfile with your favorite text editor and paste the public key for your key pair into the file, for example:Copyssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe53pcjqP3maAhDFcvBS7O6V hz2ItxCih+PnDSUaw+WNQn/mZphTk/a/gU8jEzoOWbkM4yxyb/wB96xbiFveSFJuOp/d6RJhJOI0iBXr lsLnBItntckiJ7FbtxJMXLvvwJryDUilBMTjYtwB+QhYXUMOzce5Pjz5/i8SeJtjnV3iAoG/cQk+0FzZ qaeJAAHco+CY/5WrUBkrHmFJr6HcXkvJdWPkYQS3xqC0+FmUZofz221CBt5IMucxXPkX4rWi+z7wB3Rb BQoQzd8v7yeb7OzlPnWOyN0qFU0XA246RA8QFYiCNYwI3f05p6KLxEXAMPLENote
For more information about creating a key pair, see Creating a Key Pair Using Amazon EC2. For more information about retrieving a public key from an existing key pair, see Retrieving the Public Key for Your Key Pair on Linux.
-
You should now be able to log into the newuser account on your
instance via SSH using the private key that matches the public key from Step 6.
To remove a user from the system
If a user account is no longer needed, you can remove that account so that it may no longer be used.
-
To delete a user account, the user's home directory, and the user's mail spool, execute the userdel -r command followed by the user name you wish to delete.
Copy[ec2-user ~]$sudo userdel -rolduserNote
To keep the user's home directory and mail spool, omit the
-roption.

