How to Create a User with Root Privileges on Ubuntu

The first thing you need to do when setting up a server or VPS.

Matthias Hagemann
2 min readJan 6, 2018
Photo by Crew on Unsplash

The root user is the administrative user that has broad privileges. You are discouraged from using it on a regular basis because its power can cause destructive changes, even by accident. It is best practice to immediately create another user account that will be used for your day-to-day maintenance.

I’ve personally performed this tutorial on an Ubuntu droplet at DigitalOcean. I highly recommend their infrastructure for their affordable prices, worldwide data centers and extensive documentation. If you want to start a droplet with a $100 credit, simply follow this link:

We will set up an alternative user account with a reduced scope of influence for day-to-day work but show you how to gain increased privileges during the times when you need them.

1. Start with the root user

Once you are logged in as root, we’ll add the new user account that we will use to log in from now on. If you are on a user other than root, use su - root in the terminal to switch to the root user.

2. Create a new user

This example creates a new user called matt, but you should replace it with a username that you like:

$ adduser matt

You will be asked a few questions, starting with the account’s password, followed by optional profile information such as your full name. It is not required that you fill up the fields, so you can skip them if you wish.

3. Assign heightened privileges to the new user

We may sometimes need to do administrative tasks. To avoid having to log out of our normal user and log back in as the root account, we can set up what is known as superuser for our normal account. This will allow that user to run commands with administrative privileges by putting the word sudo before each command. That’s why you often see tutorials prepending sudo in front of its commands.

To add superuser privileges to our new user, we need to add the new user to the “sudo” group. By default, on Ubuntu, users who belong to the “sudo” group are allowed to use the sudo command.

As root, run this command to add your new user to the sudo group. As usual, replace matt with your user’s name:

$ usermod -aG sudo matt

Now your user can run commands with superuser privileges.

--

--