Creating a new user on an instance

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

  1. Log into your instance using the Key Pair assigned to it and the default user assigned to it.
  2. 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
    
    You are prompted for a password along with additional details about the user.
  3. Check to confirm the user exists.
    ubuntu@instance:~$ ls -la /home
  4. 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.

  1. 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:~$ 
    
  2. Run the following command to give your new user sudo privileges:
    ubuntu@instance:~$ sudo usermod -aG sudo newuser
  3. Switch to the new user to confirm the new privileges.
    ubuntu@instance:~$ sudo su newuser
  4. 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.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?