How to Add a User and Grant Root Privileges on Ubuntu 16.04

Ubuntu 16.04 LTS provides you the ability to add a user for anyone who plans on accessing your server.  Creating a user is a basic setup but an important and critical one for your server security. In this tutorial, we will create a user and grant administrative access, known as root, to your trusted user.

Pre-Flight Check

  1. Open a terminal and log in as root.
  2. Work on a Linux Ubuntu 16.04 server

Creating a User with Root Privileges

Step 1:  Add The User

Create a username for your new user, in my example my new user is Tom:

[pastacode lang=”less” manual=”adduser%20tom” message=”” highlight=”” provider=”manual”/]

You’ll then be prompted to enter a password for this user.  We recommend using a strong password because malicious bots are programmed to guess simple passwords. If you need a secure password, this third party password generator can assist with creating one.

[pastacode lang=”less” manual=”~%23adduser%20tom%0AAdding%20user%20’tom’%20…%0AAdding%20new%20group%20%60tom’%20(1002)%20…%0AAdding%20new%20user%20%60tom’%20(1002)%20with%20group%20%60tom’%20…%0ACreating%20home%20directory%20%60%2Fhome%2Ftom’%20…%0ACopying%20files%20from%20%60%2Fetc%2Fskel’%20…%0AEnter%20new%20UNIX%20password%3A%0ARetype%20new%20UNIX%20password%3A%0Apasswd%3A%20password%20updated%20successfully%0A” message=”” highlight=”” provider=”manual”/]

Note:

Usernames should be lowercase and avoid special characters. If you receive the error below, alter the username.

[pastacode lang=”less” manual=”~%23adduser%20Tom%0Aadduser%3A%20Please%20enter%20a%20username%20matching%20the%20regular%20expression%20configured%0A%20via%20the%20NAME_REGEX%5B_SYSTEM%5D%20configuration%20variable.%20%0AUse%20the%20′–force-badname’%20option%20to%20relax%20this%20check%20or%20reconfigure%20NAME_REGEX.” message=”” highlight=”” provider=”manual”/]

Prompts will appear to enter in information on your new user.  Entering this information is not required and can be skipped by pressing enter in each field.

[pastacode lang=”less” manual=”Enter%20the%20new%20value%2C%20or%20press%20ENTER%20for%20the%20default%0AFull%20Name%20%5B%5D%3A%0ARoom%20Number%20%5B%5D%3A%0AWork%20Phone%20%5B%5D%3A%0AHome%20Phone%20%5B%5D%3A%0AOther%20%5B%5D%3A” message=”” highlight=”” provider=”manual”/]

Lastly, the system will ask you to review the information for accuracy.  Enter Y to continue to our next step.

[pastacode lang=”less” manual=”Is%20the%20information%20correct%3F%20%5BY%2Fn%5D%20Y” message=”” highlight=”” provider=”manual”/]

Step 2: Grant Root Privileges

Assigning a user root access is to grant a user the highest power.  My user, Tom, can then make changes to the system as a whole, so it’s critical to allow this access only to users who need it. Afterward, Tom will be able to use sudo before commands that are usually designed to be used by the root user.

[pastacode lang=”less” manual=”usermod%20-aG%20sudo%20tom” message=”” highlight=”” provider=”manual”/]

Step 3: Verify New User

As root, you can switch to your new user with the su – command and then test to see if your new user has root privileges.

[pastacode lang=”less” manual=”su%20-%20tom” message=”” highlight=”” provider=”manual”/]

If the user has properly been granted root access the command below will show tom in the list

[pastacode lang=”less” manual=”grep%20’%5Esudo’%20%2Fetc%2Fgroup” message=”” highlight=”” provider=”manual”/]

Output:

[pastacode lang=”less” manual=”sudo%20%3A%20x%20%3A%2027%20%3A%20tom” message=”” highlight=”” provider=”manual”/]

 

 

 

Categorized in: