How to Create a Sudo User on Ubuntu and other Debian-based Linux distributions

Razet · · 3617 Views
How to Create a Sudo User on Ubuntu  and other Debian-based Linux distributions

The sudo command is intended to permit users to run programs with the security privileges of another user, by default the root user.

In this article, you will learn how to create a new user with sudo access on Ubuntu OS. You would then be able to utilize this user to run admin commands without a need to signing in to your Ubuntu system as a root user.

Steps to Create a Sudo User

Follow the steps below to create a new user and give it sudo privileges. If you need to enable sudo access to an existing user, jump to step 3.

1. Log in to your server.

Log in to your system as the root user:

ssh root@server_ip_address

2. Create a new user

use adduser command to create a new user as shown below, and don't forget to replace username with the user name that you want to create:

adduser username

You will be prompted to set and confirm the new user password.

# Output:

Adding user `username' ...
Adding new group `username' (1001) ...
Adding new user `username' (1001) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully

Once you set the password the command will make a home directory for the user, copy a few configuration files in the home directory, and prompts you to set the new user’s information. If you want to leave all of this information blank just press ENTER to accept the defaults.

# Output:

Changing the user information for username
Enter the new value, or press ENTER for the default
    Full Name []:
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
Is the information correct? [Y/n]

3. Add the new user to the sudo group

To add the user you created to the sudo group use the usermod command:

usermod -aG sudo username

Test the sudo access

Switch to the newly created user:

su - username

Use sudo to run the whoami command:

sudo whoami

If the user have sudo privileges then the output of the whoami command will be “root”:

# Output:


Please login or create new account to add your comment.

You may also like:

Understanding Linux File Permissions and Ownership

Linux file permissions are a critical cornerstone in the architecture of Linux systems, serving as a fundamental aspect of their security model. They meticulously define who can (...)
Harish Kumar

How To Install NVM (Node Version Manager) on Ubuntu System?

This tutorial will assist you with installing NVM on the Ubuntu machine. Additionally, allow you to install different node versions and other useful examples.
Harish Kumar

Install Laravel Valet Linux+ development environment on Ubuntu System

The official Laravel Valet development environment is great if you are an Apple user. But there is no official Valet for Linux or Window system.
Harish Kumar

Install and Setup Oh-My-Zsh on Ubuntu System

In this post, I will show you how to install ZSH (Z-Shell). Then, we set up the oh-my-zsh framework for managing ZSH. We will likewise show you how to change the ZSH theme and (...)
Harish Kumar

10 Things to Do After Installing Ubuntu Operating System

In this article, I will show you 40 things you can do after installing Ubuntu on your system. This isn't restricted to a specific version of Ubuntu; you can follow these on any (...)
Harish Kumar

Ubuntu Installation step by step guide with disk partitioning

Ubuntu is the most loved OS for many desktop users, particularly for developers. Canonical releases new Ubuntu versions every six months with free support for nine months and every (...)
Harish Kumar