Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Add a User with Root Privileges on Ubuntu 18.04

Using the root account all the time is risky. This guide shows how to make a new user who can run admin commands when needed. You need root access to follow it.

Web Hosting2 min read10 steps5 screenshots

What is root?

Root is the all-powerful account on a Linux server. It can change or delete anything. One wrong command can break the server. A safer way is to use a normal user. That user borrows root power only when it types sudo before a command. Sudo means "do this as the boss".

Steps

  1. Log in to your server as root with SSH. SSH is a safe way to type commands on a faraway server. Your welcome email has your login details.
  2. Create the new user. Replace sam with the name you want:
    adduser sam
    This command makes the user and asks you for a password.
    adduser
  3. Type a strong password and press Enter. Type it again to confirm. A strong password is long and mixes letters, numbers and symbols.
  4. Fill in the extra questions, such as full name. You can press Enter to skip them.
  5. Type Y when it asks if the information is correct.
  6. Give the user admin rights:
    usermod -aG sudo sam
    This command adds the user to the sudo group. A group is a list of users who share the same rights.
    Output
  7. Check the group:
    groups sam
    You should see sudo in the list.

Test the new user

  1. Switch to the new user:
    su - sam
  2. Run a test command with sudo:
    sudo ls /root
    This command lists the root folder. Only admins may see it.
  3. Type the user's password. If you see a file list, it works.
    User specification

Next time, log in straight as sam over SSH.

Remove sudo rights

To take admin power away, run this as root:

deluser sam sudo

This command removes the user from the sudo group, but keeps the account.

Tip: Ubuntu 18.04 is an older release. Newer Ubuntu versions use the same commands.

Quick recap

  • Do not use root for daily work.
  • Make a user with adduser.
    su tom
  • Add the user to the sudo group with usermod -aG sudo.
    sudo apt
  • Test with sudo before you log out as root.