Overview
When you create an instance, a default username is created. You can use this to log in and configure the instance.
If you're adding websites to your instance, it's recommended to create separate users for each site to further secure each one. For example, having a user who only has access to the one website will limit the havoc that could be caused should that user become compromised. This also limits the danger that could be caused by rogue plugins or themes. The instance itself will be safe, containing the damage just to that user account.
Creating 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'.
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.
Assign the 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.