Sudo

Create a New Sudo User on Ubuntu

By default, each file in Linux has its own permissions and directories. These permissions determine access rights or privileges that users have on the file. If you own a file or a directory, you can pretty much do anything you want with it – you can access it, edit it, rename and even delete it.

But not all users are the same. One unique user in the Linux system is the root user. The root user is an administrative user with the highest privileges and is not bound by any permission restrictions. The user can do pretty much anything. This includes installing and uninstalling programs, accessing and modifying system files, and customizing the system.

The root user can also break the system, whether intentionally or accidentally – which is why it’s not recommended to log in and run the system as the root user. It only takes one wrong command to crash the system. For this reason, it’s always recommended to run commands as a sudo user.

What is a sudo user?

Since administering the Linux system as the root user is highly discouraged, a system administrator needs to grant a regular user some level of privilege to execute some (or all) root commands.

Sudo is a program that grants regular users permission to run commands with root privileges or as another user. A sudo user is, therefore, a regular Linux user with elevated privileges to run commands as a root user or another regular user, the default being the root user. In addition, you can configure sudo to restrict a sudo user to a handful of commands or allow them to run all commands as the root user.

How to create a sudo user

To create a sudo user on Ubuntu 20.04, follow the steps outlined.

Create a new regular user using the adduser command. Here, haleeth is our new user.

adduser haleeth

The command does a couple of things. First, It creates a new user and primary group called haleeth, and then adds the user to the group. Next, a home directory for the user is created, and configuration files are copied into it. Thereafter, you will be prompted to type in the new user’s password. Be sure to provide a strong password and confirm it.

Once the user’s password is set, some additional information will be required of you. Fill in where necessary or leave it blank by hitting ENTER if the information is not applicable.

How to Create a New Sudo User & Manage Sudo Access on Ubuntu 20.04

To confirm that the newly added user was created, view the /etc/passwd file using the cat command. This provides information such as the UID (User ID), GID (Group ID), and the path to the home directory.

cat /etc/passwd | grep haleeth

Similarly, you can retrieve the user details using the id command.

id haleeth

Add the new user to the sudo group.

A sudo group is a group of superusers that have privileged access to root commands. With that in mind, proceed and add the new user to the sudo group using the usermod command as follows.

usermod -aG sudo haleeth

To verify that the user has been added to the sudo group, use the id command.

id haleeth

From the output, we can see that the user now belongs to two groups: haleeth and sudo. Alternatively, you can also run the groups command to only display the groups that the user belongs to.

groups haleeth

The new user is now a sudo user and has unrestricted access to root privileges.

Test sudo

With the sudo user already in place, we are going to proceed and test the user. So, switch to the sudo user using the su command.

su - haleeth

The command places you in the user’s home directory path. The syntax for using sudo is indicated below

sudo command-to-be-executed

As an example, we are going to update the package lists of our system. So, invoke sudo followed by the command to be executed.

sudo apt update

When prompted, type in the password of the user and hit ENTER. The command will execute successfully – a confirmation that the user has successfully been added to the sudo group and can now perform elevated system tasks.


Posted

in

by

Tags: