Add/Remove users in/from the SUDO group

The SUDO ( Super-user do) is a program designed to allow users to execute commands with the security privileges of another user.

This section will guide you through the process of adding a new user and provide it super user access.

First SSH to your computer via tools like Putty or open terminal if you working in a GUI environment. Change to root, if not. If you have another user with sudo access, you can use sudo command also to create a new user. But the normal user should be in sudoers group before getting the permissions to execute the command with sudo privilege. I assume you are now log in as a root user.

PuTTY connecting to remove Linux Server

Create a new user account , if not done already.

adduser username
Adding User using Terminal

Provide all the information needed. This will create a home directory for the user "testuser". If you want to create a user without "HOME" folder, you can use useradd USERNAME command. You have to use -m , otherwise no home directory will be created.
If you want to specify the path of the home directory, use -d and specify the path: useradd -m -d /PATH/TO/FOLDER USERNAME

Note: You can then set the password with

Before adding this user to a sudo group, let's see the impact executing sudo functions without enough privileges.

Checking normal user with sudo access

Clearly, you can see that the user "testuser" has been denied running commands with sudo permissions.

To add a user to the sudo group, you can use usermod command.

usermod -aG sudo username

Now if you try to execute any command with the SUDO command beforehand for user "testuser", you should be able to run them.

We have now seen how to create a user with sudo privileges. If you want to remove any user from this sudo group, you can execute follwing commands as root privilege user.

gpasswd -d testuser sudo
Removing user from a sudo group

How to Find Out Who Tried to Use Sudo Without Permission ?

When a user tries to run a sudo command and is not authorized to run sudo commands, the error message will be logged.
Within Debian the errors are sent to a file called /var/log/auth.log.
On systems such as Fedora and CentOS the errors are logged to /var/log/secure.
You can use follwing command to acces the log file
tail /var/log/auth.log | more
Error Message Log


Anup Chhetri

IT system administrator

You may also like...

error: Content is protected !!