Getting this error trying to add user to sudoers
# usermod -aG sudo operationsuser usermod: group 'sudo' does not exist
It looks like you’re trying to add a user to the sudo
group, but the group doesn’t exist on your system. This is common in some Linux distributions where the sudo
group is not predefined. Here’s a detailed guide to fix this issue: Step-by-Step Guide
- Check Existing Groups: First, let’s verify if the
sudo
group exists or if there’s an equivalent group likewheel
:
# cat /etc/group | grep sudo # cat /etc/group | grep wheel
- Create the
sudo
Group (if it doesn’t exist): If thesudo
group is not found, you can create it using:
# sudo groupadd sudo
- Add User to the
sudo
Group: Now, add your user (operationsuser
) to thesudo
group:
# sudo usermod -aG sudo operationsuser
- Configure Sudoers File: Edit the sudoers file to ensure the
sudo
group has the necessary permissions:
# sudo visudo
Look for a line like this and uncomment it, if it’s not there, please add it (remove the #
at the beginning):
%sudo ALL=(ALL:ALL) ALL
- Verify the Changes: To ensure the changes take effect, you can check the user’s group memberships:
# groups operationsuser
- Test Sudo Access: Switch to the user and test if they have sudo access:
> su -
The command should return a password prompt, provide your password and you should have root privileges. Alternative: Using the wheel
Group In some distributions like CentOS, the wheel
group is used instead of sudo
. If you find the wheel
group, you can add the user to it:
- Add User to the
wheel
Group:
# sudo usermod -aG wheel operationsuser
- Configure Sudoers File: Edit the sudoers file:
# sudo visudo
Ensure the following line is uncommented:
%wheel ALL=(ALL) ALL
- Verify and Test: Follow the same verification and testing steps as above.
This should resolve the issue and grant operationsuser
the necessary sudo privileges. If you encounter any issues or have further questions, feel free to ask!