How to Create a Non-root User on Your Server | HostAdvice

How to Create a Non-root User on Your Ubuntu 18.04 VPS or Dedicated Server

If you are spinning a new Ubuntu 18.04 server, you may need to create a new non-root user with sudo privileges.  Logging on your Linux server as the root is not a good practice because a single mess can wipe your entire server.

Creating a new user with sudo permissions allows you to do administration tasks with elevated privileges only when necessary.  Also, most administrators find it safer to disable root login because it can be potentially dangerous if the password of the server is compromised.

So on top of protecting your Ubuntu 18.04 server with authentication keys, you should create a new user with sudo privileges. Only add users who you want to do administrative tasks on the sudo group.

Sudo is an acronym for “superuser do” and is simply a program that allows a currently logged in user to run programs with the privileges of a super admin. In this guide, we are going to show you how to do this on you VPS machine running Ubuntu 18.04 operating system.

Prerequisites

  • Ubuntu 18.04 VPS
  • Root access to your Linux machine

Special note: HostAdvice’s hosting reviews allow you to consult with thousands of users before purchasing a hosting plan. If you are looking to purchase a Ubuntu VPS plan, consult the VPS hosting reviews or Linux Hosting reviews.

Step 1: Connect to your server

Before you create the new user, we need to connect to the server. You can use Putty if you are using Windows or any other command line tool that allows secure connections via SSH. Remember, you will need your server’s public IP address and your root user’s password.

Step 2: Add the new user

Once you are connected to the server. Run the command adduser to create your new user. Please note you can also use the natively binary compiled useradd command but it is less user-friendly than the Perl script adduser command.

So, on a terminal window, type the following:

$ sudo adduser <username>

Remember to replace username with the preferred name of your new user. For instance, if you want to add a new user called ‘james’ the syntax should be:

$ sudo adduser james

You will be prompted to enter a password for the new user, Full Name, Room number and phone details. You can press Enter if you don’t want to enter a value. Then, press Y once you get a prompt to confirm the details as shown below:

Step 2: Add the new user

Please note if a duplicate is detected, you will get the error below:

useradd: user <username> already exists

Step 3: Add the new user to the sudo group

Your new user above is created with regular privileges and if you try to run any sudo task, you will get an error like, “james is not in the sudoers file.  This incident will be reported.” In order to allow the user to do administrative tasks e.g. rebooting the server, creating new users or installing applications, we need to run the command below:

$ sudo usermod -aG sudo james

Remember to replace “james” with the username that you created above.Your new user should be successfully added to the sudo program.

Step 4: Testing the new user

We can use the su command on our Ubuntu 18.04 server to switch to the new user that we created above; su is an acronym for substitute user. It allows the currently logged in user to change the session without having to logout first.

To do this, we run the command below:

$ su - james

Output:

Step 4: Testing the new user

You can try to run a command like sudo dpkg-reconfigure tzdata to see if your new user can run administrative task.

Output

Step 4: Testing the new user

If you see the output above, your new user has been successfully added to the list of sudoers.

Conclusion

Creating a non-root user with sudo privileges is not complicated if you follow the above steps. This will provider a safer manner for your Ubuntu 18.04 server administrators to do tasks while minimizing potential dangers. Also running tasks as non-root users is very useful when your server goes live because it makes more difficult for malicious programs to access your critical files. Remember, you can create more sudo users as necessary by repeating the procedure above.

Check out the top 3 VPS services:

Hostinger
MYR 6.35 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.9
  • Support
    4.9
  • Features
    4.8
  • Reliability
    4.7
  • Pricing
    4.5
Kamatera
MYR 15.98 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Hosting.com
MYR 11.95 /mo
Starting price
Visit Hosting.com
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0

How to Install & Configure the Caddy web server on an Ubuntu 18.04 VPS

Caddy is the only new server's that secure by default. It's growing in popularit
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install Apache Cassandra on an Ubuntu 18.04 VPS or Dedicated Server

This tutorial will help you install and configure Apache Cassandra (an opensourc
less than a minute
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Set Up Cron Jobs on Your Ubuntu 18.04 Dedicated Server or VPS

This guide shows webmasters and administrators how to set up cron jobs on your U
less than a minute
Idan Cohen
Idan Cohen
Marketing Expert

How to Backup Your MySQL Database on an Ubuntu 18.04 VPS or Dedicated Server

This article shows you how to back up a MySQL database on a Linux Ubuntu 18.04 s
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert
Click to go to the top of the page
Go To Top
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.