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?
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:
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.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"
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
sudo gpasswd -a $USER sudo
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:Running the command
adduser myuser sudo
reported erroradduser: The user 'myuser' does not exist.
. After reading this answer, I first ran the command to create the user:Then ran the following command:
The user myuser was successfully added to the sudo group.
Here's how I setup a non-root user with the base image of
ubuntu:18.04
:What happens with the above code:
foo
is created.foo
is added to the both thefoo
andsudo
group.uid
andgid
is set to the value of999
./home/foo
./bin/bash
.sed
command does inline updates to the/etc/sudoers
file to allowfoo
androot
users passwordless access to thesudo
group.sed
command disables the#includedir
directive that would allow any files in subdirectories to override these inline updates.Use usermod. Add the sudo permission with the following command:
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.