Overview
Every instance comes with a default username, created for you when the instance is created, that you can use to log in and configure it.
You can also create a separate user for each website you host on the instance. This keeps sites isolated from one another: if a user account (or a rogue plugin or theme on that site) is compromised, the damage stays contained to that one user account, and the instance itself remains safe.
How do I create a new user?
- Log into your instance using the Key Pair assigned to it and the default user assigned to it.
- Create the new user once logged in.
This example assumes an Ubuntu instance with a default user named 'ubuntu'.
In the example below, the new user is named 'newuser'.
You are prompted for a password along with additional details about the user.ubuntu@instance:~$ sudo adduser newuser
- Check to confirm the user exists.
ubuntu@instance:~$ ls -la /home
- Switch to the new user.
ubuntu@instance:~$ sudo su newuser
Your terminal prompt now changes to the new username:
newuser@instance:~$
You can now run commands and manage your website under this new username.
How do I assign my new user 'sudo' privileges?
Depending on your user's needs, you may need to assign them 'sudo' privileges to install software. This should only be done if you trust the user.
- Make sure you're logged in as the default user of your instance. For an Ubuntu instance, the default user is 'ubuntu'. If you're still logged in as the new user, just type 'exit' until the shell username returns to the default user:
newuser@instance:~$ exit ubuntu@instance:~$
- Run the following command to give your new user sudo privileges:
ubuntu@instance:~$ sudo usermod -aG sudo newuser
- Switch to the new user to confirm the new privileges.
ubuntu@instance:~$ sudo su newuser
- Run the 'groups' command to see what groups this user has access to:
newuser@instance:~$ groups newuser sudo
Since 'sudo' is in the list, you can now run sudo commands with this new username.