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

In this guide we will show you how to create a new user on a Ubuntu machine and give it sudo access. You can then use this user account to execute administrative commands without a need to logging in to your Ubuntu server as a root user.

How to use sudo

To use sudo, simply prefix the command with sudo and a space:

Steps to create a sudo user :

Follow the steps below to create a new user account and give it sudo access. If you want to configure sudo for an existing user, skip to step 3.

Step 1: Log in to your server.

Log in to your system as the root user:

$ ssh root@server_ip_address  


$ ssh root@hostname

Step 2:  Create a new user account.

Create a new user account using the adduser command. Don’t forget to replace username with the user name that you want to create:

$ adduser username

Step 3: Add the new user to the sudo group

By default on Ubuntu systems, members of the group sudo are granted with sudo access. To add the user you created to the sudo group use the usermod command:

usermod -aG sudo admin-devops

Step 4: Test the sudo access

Switch to the newly created user:

$ su - username

Use the sudo command to run the whoami command:

$ sudo whoami

Exemple :

Start the server vm-rcherara-devops


Connecte to the server vm-rcherara-devops


Adding the user admin-devops  to the sudoers group