In /etc/sudoers I see this:

# Allow members of group sudo to execute any command after they have
# provided their password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL

So how do I add a user to that sudo group?

  • Is anyone else here trying to get sudo to work with no password on ubuntu 17? – Adam F May 4 '17 at 17:27
  • @AdamF look here. Next time ask a new question if you want a speedier response. ;-) – Fabby May 3 '18 at 22:27
  • Coffe-grinder: would you mind changing your acceptance to the most highly upvoted answer as that's a better way to do it? (no password at all) – Fabby May 3 '18 at 22:28
sudo usermod -aG sudo <username>

The a is very important. Without it they'll be removed from all other groups. You will need to either restart your shell/terminal or log out and back in for this to take effect.

See also:

| improve this answer | |
  • I did what u recommended, but terminal told me bash: sudo: command not found, why? – Teifi Jan 21 '13 at 12:23
  • @Teifi, that means you probably don't have sudo installed or, for some weird reason, it's not in your path. What happens when you run which sudo? – n0pe Jan 22 '13 at 16:33
  • New terminals were not enough. Ended up rebooting for another reason and now it works. Probably log-out/in. – deed02392 Jul 8 '14 at 15:35
  • I know a is for append, but i think it will be more usefull to have append as default behavior. Creating an alias is easy so that will be the way to have groupadd group then just append it. I did the command without -a once today as i didn't remember the -a argument. – m3nda Apr 12 '17 at 18:59
  • Although this is an Ubuntu forum, For CentOS I had to do sudo usermod -aG sudo <username>. Because there was no easy way for me to find this out. – akki May 25 '19 at 14:03

You can either use the user management GUI for it (same place where you create users), or use sudo adduser <username> sudo in the command line.

| improve this answer | |
  • 2
    This is also referred to in the ubuntu documentation on RootSudo albeit they refer to the admin group instead of the sudo group – icc97 Mar 5 '12 at 8:27
  • 9
    +1: this is the most easy-to-remember, simple and intuitive way to add a user to a group! – Andrea Corbellini Dec 28 '12 at 17:14
  • This gives me an error saying Usage: adduser [options] LOGIN\n adduser -D\n adduser -D [options]\n – akki May 25 '19 at 13:58

You can also use a graphical interface. Click on the gear on the top right of the panel, then select "System Settings" and then "User Accounts"

You need to click the little unlock button to be able to edit things in this window. Then click on the person's account and select the proper dropdown for "Account Type"

enter image description here

| improve this answer | |
  • I have Ubuntu 10.10 but my graphic interface is someway locked. It opens but I when buttons are pressed nothing happens. I suppose is something related to the privileges (I'm actually sudoer). How can I solve this issue? – linello Jan 18 '13 at 9:49
  • Did you click the 'unlock' button? – daboross Jun 10 '13 at 2:22
  • Nice animation! I'd like to do such a gif animation to show new features of my web app ? I'm on Lubuntu 16.04... – Stephane Sep 21 '17 at 14:41

Its really simple if you are using Unity as your desktop environment.

If you have created a user already then you can simply change it from Standard to Administrator, else make sure that you selected Administrator when creating a new one.

Don't forget to unlock before trying to change it

enter image description here

| improve this answer | |

sudo gpasswd -a $USER sudo

| improve this answer | |

I am late to the party, but this answer might help someone that uses Ubuntu inside a Docker container.

I recently created a Docker container based on Ubuntu 16.04.1.

By default, the Docker Ubuntu image is a stripped down version of Ubuntu, which does not have a vast majority of common tools including sudo.

Besides, by default, the user is logged in to the Docker container as root.

Therefore, I started the container with the docker run command, and installed the 'sudo' package:

root@default:/# apt-get install sudo

Running the command adduser myuser sudo reported error adduser: The user 'myuser' does not exist.. After reading this answer, I first ran the command to create the user:

root@default:/# adduser myuser

Then ran the following command:

root@default:/# adduser myuser sudo
Adding user `myuser' to group `sudo' ...
Adding user myuser to group sudo

The user myuser was successfully added to the sudo group.

| improve this answer | |

Use usermod. Add the sudo permission with the following command:

usermod -aG sudo <your username>

Please note that you'll have to use the root account to do this or use another account that has sudo permissions. If you don't have access to another account for some reason and you don't know the root password, you'll need an Ubuntu (or another Linux distro) live CD and then you'll need to chroot into your Ubuntu filesystem and run the above command from inside the chroot.

| improve this answer | |

Here's how I setup a non-root user with the base image of ubuntu:18.04:

    groupadd -g 999 foo && useradd -u 999 -g foo -G sudo -m -s /bin/bash foo && \
    sed -i /etc/sudoers -re 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g' && \
    sed -i /etc/sudoers -re 's/^root.*/root ALL=(ALL:ALL) NOPASSWD: ALL/g' && \
    sed -i /etc/sudoers -re 's/^#includedir.*/## **Removed the include directive** ##"/g' && \
    echo "foo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
    echo "Customized the sudoers file for passwordless access to the foo user!" && \
    echo "foo user:";  su - foo -c id

What happens with the above code:

  • The user and group foo is created.
  • The user foo is added to the both the foo and sudo group.
  • The uid and gid is set to the value of 999.
  • The home directory is set to /home/foo.
  • The shell is set to /bin/bash.
  • The sed command does inline updates to the /etc/sudoers file to allow foo and root users passwordless access to the sudo group.
  • The sed command disables the #includedir directive that would allow any files in subdirectories to override these inline updates.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.