- How do I add a user to the «sudo» group?
- How To Add User To Sudoers & Add User To Sudo Group on Ubuntu
- Steps to Add Sudo User on Ubuntu
- Step 1: Create New User
- Step 2: Add User to Sudo Group
- Step 3: Verify User Belongs to Sudo Group
- Step 4: Verify Sudo Access
- How to Add Users to sudo group in Linux
- How to Add Users to sudo group in Linux
- Add Users to sudo group in Linux
- Adding users to sudoers file in Linux
- SUPPORT US VIA A VIRTUAL CUP OF COFFEE
How do I add a user to the «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.
@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 ?
New terminals were not enough. Ended up rebooting for another reason and now it works. Probably log-out/in.
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.
Although this is an Ubuntu forum, For CentOS I had to do sudo usermod -aG sudo
You can either use the user management GUI for it (same place where you create users), or use sudo adduser sudo in the command line.
This is also referred to in the ubuntu documentation on RootSudo albeit they refer to the admin group instead of the sudo group
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»
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?
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.
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
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 Done.
The user myuser was successfully added to the sudo group.
How To Add User To Sudoers & Add User To Sudo Group on Ubuntu
The sudo command is the preferred means to handle elevated permissions. In supported versions of Ubuntu, using the sudo command will grant elevated permissions for 15 minutes.
Standard user accounts are restricted from performing sensitive tasks, such as viewing the contents of the /root directory. This prevents the accidental use of commands with massive consequences. It also makes it more difficult for intruders to compromise a system. However, sometimes you need to run an administrative command. Sudo – or Super User Do – grants you privileges to run sensitive tasks.
This simple tutorial will show you how to add a new user on Ubuntu and provide sudo access.
- A system running a supported version of Ubuntu
- Access to a root user account or another account with sudo privileges
- Access to a terminal window/command line (Ctrl–Alt–T)
Note: Linux Sudo Command tutorials also available for CentOS and Debian.
Steps to Add Sudo User on Ubuntu
Step 1: Create New User
1. Log into the system with a root user or an account with sudo privileges.
2. Open a terminal window and add a new user with the command:
The adduser command creates a new user, plus a group and home directory for that user.
You may get an error message that you have insufficient privileges. (This typically only happens for non-root users.) Get around it by entering:
3. You can replace newuser with any username you wish. The system will add the new user; then prompt you to enter a password. Enter a great secure password, then retype it to confirm.
4. The system will prompt you to enter additional information about the user. This includes a name, phone numbers, etc. – these fields are optional, and can be skipped by pressing Enter.
Step 2: Add User to Sudo Group
Most Linux systems, including Ubuntu, have a user group for sudo users. To grant the new user elevated privileges, add them to the sudo group.
In a terminal, enter the command:
Replace newuser with the username that you entered in Step 1.
Again, if you get an error, run the command with sudo as follows:
sudo usermod -aG sudo newuser
The -aG option tells the system to append the user to the specified group. (The -a option is only used with G .)
Note: Usermod command is a useful tool for user management. To learn more about its options, refer to our guide How To Use The Usermod Command In Linux.
Step 3: Verify User Belongs to Sudo Group
Enter the following to view the groups a user belongs to:
The system will respond by listing the username and all groups it belongs to, for example: newuser : newuser sudo
Step 4: Verify Sudo Access
Replace newuser with the username you entered in Step 1. Enter your password when prompted. You can run commands as normal, just by typing them.
However, some commands or locations require elevated privileges. If you try to list the contents of the /root directory, you’ll get an access denied error: ls /root
The command can be executed with:
The system will prompt for your password. Use the same password you set in Step 1. You should now see the contents of the /root directory.
Now you know how to add and create a user with sudo privileges on Ubuntu.
Before sudo, users would log in to their systems with full permissions over the entire system with the su command. This was risky as users could be exploited by tricking them into entering malicious commands. These vulnerabilities were solved by limiting account privileges. However, administrators still had to log out of their account and into an admin account to perform routine tasks.
The sudo command in Ubuntu strikes a balance – protecting user accounts from malicious or inadvertent damage while allowing a privileged user to run administrative tasks. To learn more about the difference between these commands, check out Sudo vs. Su.
How to Add Users to sudo group in Linux
In this guide, we are going to learn how to add users to sudo group in Linux. More often than not, you want, as a non-root user, to run commands with elevated privileges in Linux. So the only way this can happen is to give user sudo privileges by adding them to a sudo group or to sudoers file.
How to Add Users to sudo group in Linux
sudo group in Debian and its derivatives is called wheel group in CentOS and similar derivatives.
A user can be given sudo privileges by being added to the sudo / wheel group or by being added to the sudoers file, /etc/sudoers .
So what is the difference between sudo/wheel group and sudoers file?
The sudo/wheel group has the privileges it has based on what is defined on the sudoers file. In sudoers file, you will see the lines below;
# Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL
## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL
NOTE that a group is prefixed with % .
So based on the two lines above, sudoers security policy requires that users authenticate themselves before they can use sudo command.
However, a password is not required if the invoking user is root, if the target user is the same as the invoking user, or if the policy has disabled authentication for the user or command.
Add Users to sudo group in Linux
To add user to wheel or sudo group, you can use the usermod command in the following syntax;
usermod -aG sudo/wheel USERNAME
- a means add the user to the supplementary group that will be specified with -G option.
- G specifies the supplementary groups to which the user is being added.
- sudo/wheel specifies the group to add the user
- USERNAM specifies the name of the user being added to the sudo group.
For example, On Debian and its derivatives, to add a user called john to sudo group;
To confirm the groups of the user, use id command.
id john uid=1002(john) gid=1002(john) groups=1002(john),27(sudo)
On RHEL and its derivatives like CentOS;
id john uid=1001(john) gid=1001(john) groups=1001(john), 10(wheel)
Adding users to sudoers file in Linux
Well, you can explicitly give users sudo privileges by adding them to the sudoers file. A user whose privileges are defined in the sudoers file doesn’t necessarily have to be added to the sudo or wheel group.
To edit the sudoers file, use the visudo command. This will open the sudoers file with your default editor, usually nano if the EDITOR variable has not been set.
To use vim as your editor, simply run;
Next, run visudo command. Note that you cannot edit the sudoers file as an ordinary user with no sudo privileges.
Once you open the sudoers file, you can give a user sudoers rights as follows.
For example, to enable the user john to run commands with sudo privileges, simply add the line below on the sudoers file.
This line allows user john to run all commands with sudo upon authentication.
If you need to allow specific group of users to run the commands with sudo, simply add the line below replacing the groupname with your group.
- john or groupname : specifies the user or group being assigned the sudo privileges.
- ALL (before =): Specify the host on which the user/group can have sudo privileges. This means that the user/group can use sudo on all hosts.
- ALL:ALL (within the brackets): The ALL before the colon specifies the user running the command while the ALL after the colon specifies the group of the user running the command.
- ALL (the last section): Specifies the command that the user can run. In this case, it means any command.
Once the user is given sudo rights, they can now execute privileged commands that are allowed to execute by prefixing them with sudo.
In this guide, you have learnt how to add users to sudo group in Linux. In our next tutorial, we will learn how to allow a user to run only specific commands with sudo command.
SUPPORT US VIA A VIRTUAL CUP OF COFFEE
We’re passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!