How to Give Sudo Permission to Users on Ubuntu Linux [Beginner’s Tip]

When installing Ubuntu, you’re asked to create a user, and that user gets sudo access by default. That’s good, because you need root privileges to do things like perform updates and install packages(probably wouldn’t be too nice if any user could do that).

But what about new users you created after installing Ubuntu? What if the new user also needs sudo permissions?

In this tutorial, I’ll go over the steps you need for adding a user to sudoers in Ubuntu, from both the command line and a GUI.

The GUI method will work for the desktop version of Ubuntu, while the command line method will work for both the desktop and server versions.

Note: this tutorial is not about creating users in Ubuntu. I’m assuming any users you’re doing this for have already been created. Lastly, to give sudo access to another user, you must have sudo access yourself.

Giving sudo permissions from the command line

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

sudo usermod -aG sudo username

The above command adds the user to the sudo group, which is used to track the users who are allowed to have sudo permissions. Just adding the user to the sudo group takes care of everything. Pretty easy, right?

Let’s go over what that command just did:

  • usermod: The usermod command is used for modifying an existing user in Linux.
  • -aG: The a option means append(or add), G is for groups. So, this adds the specified group to the specified user, without touching the user’s existing groups. If you exclude the a option, the user would be removed from all its groups except sudo (you don’t want that).
  • sudo: the second sudo in the command represents the sudo group.
  • username: This is the name of the user you want to add to the sudo group.

If you don’t know the exact username, you can list the users on your system using the compgen -u command. You’ll find the username near the end of the command’s output.

How to verify if the user has sudo access

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

groups username
sudo group check

Alternatively, you can log in as the other user you just gave sudo access to and run a command with sudo. For example:

sudo echo "I am root!"

If everything’s set up correctly, it’ll output I am root!. If you get an error about the user not being in the sudoers file, try going through the instructions again, or you can use the graphical method below.

Giving 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 same command as before. Look for the same output as mentioned before.

sudo echo "I am root!"

Wrapping up

With that, you’ve given a user sudo permissions! The commands should be mostly, if not completely functional on other distros such as Debian, Fedora, or Arch Linux.

If you have any questions or suggestions, feel free to leave them in the comments.

Similar Posts

  • Sudo provides a means of limiiting root access privileges such as mounting/unmounting drives, as well as copying from privileged directories. Anyone who gives full sudo privileges is just a system destruction waiting for mr joe curious who wants to see what sudo rm /test/ * does when there is a inadvertang space before the *

  • Hunter, I know in other businesses where I have worked, they have given sudo rights to a specific command. Can you let us know how that is done?

    • Have a look in sudoers(5), what you want is Cmnd_Alias. Also look for Runas_Spec if you are more interested in running particular commands as a specific user. It’s a lot to read, but it’s well worth it with that particular manual. Most users don’t even have the slightest idea just how much power and how fine-grained a configuration sudo gives them. Don’t be one of them, read the (in this case) friendly manual.

  • No mention of newgrp. Using usermod instead of adduser is sort of rather un-Ubuntu/Debian-esque. Instead of compgen getent would work well. The command id should have been mentioned and if you don’t know the exact username you should refrain from making some user member of the sudo group. Last but not least /etc/sudoers was pretty much skipped, even though the sudo group only gains its special powers on account of being mentioned there on a Debian/Ubuntu.

    The way it’s written you could use this almost on other distros if you mentioned the wheel group. It’s a shame that the convenience command adduser wasn’t mentioned but other than the group name nothing is really specific to Debian/Ubuntu.

    • Thanks for the feedback!

      I agree that some stuff is more tailored to Debian/Ubuntu, and then some might ironically not be(or some other stuff might’ve at least been more anyway). I tried to go with what I knew best though, as I know that it’ll work for users, and it allows be to be more confident in what I talk about.

      Again though, thanks!