Create Non-Root User

Linux Tutorials

Download Create Non Root User tutorial.

In this tutorial, I will be demonstrating how to create a non-root user, with sudo privileges, on a CentOS 7 VM.

Refer to the prerequisites listed below to access the resources needed to complete this tutorial.

Prerequisites

  • VirtualBox VM with a CentOS 7 minimal install
  • root user’s password OR non-root user with sudo privileges

For instructions on how to install VirtualBox and extension pack, see my VirtualBox Install tutorial here.

If you do not already have a virtual machine, with a minimal install of CentOS 7, my other tutorial, CentOS 7 Server Install, is here.



If you already have access to a CentOS 7 minimal install VM, but have forgotten the root user’s password, see my tutorial here. You will need this password to create a non-root user. Or, you can use another non-root user that has sudo privileges.

Steps to complete tutorial:


Start Virtual Machine

From the VirtualBox Manager interface, ensure your VM is selected and click Start



Create Non-Root User with sudo Privileges

To be able to perform system operations, such as installing, and updating, packages, or managing users and services, the user performing the operations must have sudo privileges, or, be performed by the root user.

In a production environment, it is good practice NOT to login as the root user, and to NEVER perform operations while logged in as the root user. First, security, because the root user has access to everything on the system, anything done by the root user is allowed. Second, any operations performed by the root user will be logged as being done by the root user. It would be difficult to determine who did what, at a certain time, if everyone in a department knows the root user’s password.

Since this is a lab environment, I will demonstrate the creation of a non-root user that has sudo privileges, while logged in as the root user. To follow along, you will also need to know the root user’s password.

If you don’t know the root user’s password, I have a tutorial, Root User Password Reset, accessible here. Or, you can use another non-root user that already has sudo privileges.



Once CentOS 7 has started, on the login screen, enter the root user’s credentials. (Please note that you can perform the operations below using a non-root user that has sudo privileges (just add sudo before each command).

Now that we are logged in as the root user, we will create a non-root user with sudo privileges.

On the command line, execute the following commands (one after the other & enter password, when prompted):
# useradd vern                    // create new non-root user
# passwd vern                     // set non-root user’s password
# usermod -aG wheel vern          // add non-root user to ‘wheel’ group
                                  // members of ‘wheel’ group have sudo privileges



Now we will verify that our newly created non-root user has sudo privileges.

Verify sudo Privileges

On the command line, execute the following commands (one after the other & enter password, when prompted):
# su – vern          // switch to non-root user vern
$ whoami             // print the username of the current user
$ id                 // print user & group info for current user
$ sudo ls -al        // confirm non-root user has sudo privileges by executing command



Now that we have a non-root user with sudo privileges (wheel group member), we can complete the tutorial by shutting down the system.

Remember to use your newly created non-root user’s password to acknowledge the following command:
$ sudo shutdown -h now          // -h option used to halt the system



We have successfully created a non-root user with sudo privileges. Now, anytime you need to perform system operations requiring root privileges, you can use this user to ensure that you have a way to track who did what on the system.

I hope you have enjoyed completing this tutorial and found it helpful.

If you would like to see my other tutorials, they can be accessed here.

Finally, if need be, you can download this tutorial Create Non Root User.