40 C
Jaipur
Tuesday, April 13, 2021

How to Give Sudo Access to a User on Ubuntu Linux

Must read

When you install Ubuntu, you are asked to create a user and this user gets sudo access by default. This is good because you need root privileges to manage the system.

But what about new users you created later on Ubuntu? What if the new user also needs to have sudo access for some valid reasons?

In this beginner’s tutorial, I’ll show you the steps for adding a user to sudoer in Ubuntu using both GUI and command line methods.

The GUI method is suitable for the desktop version while the command line method works for both desktop and server versions of Ubuntu.

This tutorial is not about creating users in Ubuntu. I assume that the other user is already created. Needless to say that to give sudo access to another user, you must have sudo access yourself.

Add user to sudo in Ubuntu using command line

Giving a user sudo permission from the command line is a matter of a single command if you know the exact username:

sudo usermod -aG sudo username

With the above command, you are adding the user to the sudo group. Since sudo is a built-in feature of Ubuntu, it is well configured in the system. Just adding the user to sudo group takes care of the matter. Easy, right?

Let me detail the command and its option:

  • usermod: The usermod command is used for modifying an existing user in Linux.
  • -aG: The a option means append, G is for groups. This means add user to the specified group, without touching the user’s existing group. If you miss option a, the user would be removed from all its groups except sudo. That will be catastrophic.
  • sudo: this second sudo in the command represents the sudo group.
  • username: This is the name of the user you want to add as a sudoer.

If you do not know the exact username, you may list users in Linux using the compgen -u command and looking at the end of its output.

How to confirm if the user has sudo access now?

There are various ways you can check if a user has sudo access. You can check if the user is part of sudo group now:

groups username

Alternatively, you may log in as the other user you just gave sudo access to and run a command as sudo. You may also ask the user (if it’s for a real person) to check if she/he can run commands with sudo.

sudo echo "I am root!"

Give sudo access to a user on Ubuntu desktop

Giving a user sudo permissions on Ubuntu Desktop is a simple two-step process:

Step 1: Open up the Settings application, go to ‘Users’ and click ‘Unlock’. Enter your password when prompted to do so.

Unlock user settings Ubuntu

Step 2: Toggle the Administrator switch to on.

Add user as sudo on Ubuntu desktop

And that’s it! If you want to see if it worked, log in as the user you gave administrator permissions to and try running the following. It’ll tell you if everything went fine:

sudo echo "It worked!"

Did it work for you?

By now, you now know how to give a user sudo permissions in Ubuntu. The steps can be followed on many other distributions as well, at least the Debian-based ones that have similar implementation of sudo. Red Hat and CentOS have it a bit different.

If you have any questions or suggestions, please share them with me in the comments.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article