Sunday, December 10

How to create a user, add a user to sudo group and run sudo command without password in Ubuntu

More than one person should interact with the same system at the same time. As a system administrator, we have the responsibility to manage the system’s users and groups by creating and removing users and assign them to different groups. 

In Linux, you should not run the system with root privileges. But, it can also be inconvenient to have to enter the password every time when using sudo.

This is a step by step guide to creating users, add users to specific groups, and allow to run sudo command without password.  

Create or add a user using adduser command

$ sudo adduser demo


# adduser demo

You will be prompted to enter and confirm the password and user detail. create a strong password. It will create a user account, group, password, and home directory.


Adding user `demo’ …
Adding new group `demo’ (1003) …
Adding new user `demo’ (1003) with group `demo’ …
Creating home directory `/home/demo’ …
Copying files from `/etc/skel’ …
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for demo
Enter the new value, or press ENTER for the default
Full Name []: Demo User
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]

Add the user to a specific group.


I will add a user to ‘sudo’ group, you can add a user to your required group.

$ sudo usermod -aG sudo demo


usermod -aG sudo demo

If you didn’t see any warning or error message, you have done it perfectly. 

Enable sudo without a password or run a sudo command without a password.


Backup sudoers file to your backup directory. In this demo, I will keep backup files in the same directory with (.bak) extension. 

$sudo cp /etc/sudoers  /sudoers.bak

Enter your password:


# cp /etc/sudoers /sudoers.bak

Enter your password:

Edit sudoers file using text editor available on your system. I am using nano.

$sudo nano /etc/sudoers

Enter your password:


#nano /etc/sudoers

Enter your password:

Add these lines at the end of the file in /etc/sudoers. Replace ‘demo’ with your account.


Press Ctrl+o and Ctrl+x to save and close the edited sudoers file.

Final sudoers edited sample file.

Sudoers file to add user
enable sudo without password
Adding a user to sudoers file to run sudo command without password

Open a new terminal and run some commands that require root privileges.

For example : $sudo apt-get update

Now, You shouldn’t be prompted for your password.

Leave a Reply

Your email address will not be published. Required fields are marked *