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) ALLSo how do I add a user to that sudo group?
8 Answers
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:
6You 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:
root@default:/# apt-get install sudoRunning 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 myuserThen ran the following command:
root@default:/# adduser myuser sudo
Adding user `myuser' to group `sudo' ...
Adding user myuser to group sudo
Done.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:
RUN \ 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 idWhat happens with the above code:
- The user and group
foois created. - The user
foois added to the both thefooandsudogroup. - The
uidandgidis set to the value of999. - The home directory is set to
/home/foo. - The shell is set to
/bin/bash. - The
sedcommand does inline updates to the/etc/sudoersfile to allowfooandrootusers passwordless access to thesudogroup. - The
sedcommand disables the#includedirdirective that would allow any files in subdirectories to override these inline updates.
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.