How to Create and Add Users to Sudoers on Linux Mint

Adding users to the sudoers group on Linux Mint gives them administrative privileges to run commands as root. This guide covers creating new user accounts, granting sudo access to both new and existing users, and verifying that permissions work correctly. By the end, you will have a fully configured sudo user who can install software, manage services, and perform system administration tasks safely.

Understanding Sudo Access on Linux Mint

The sudo command allows regular users to execute commands with root privileges without logging in as root directly. On Linux Mint, users gain sudo access by becoming members of the sudo group. This approach is more secure than sharing a root password because it logs which user ran each privileged command and allows fine-grained control over permissions.

Linux Mint ships with the root account locked by default, meaning root has no usable password. The initial user created during installation automatically has sudo access. To grant additional users the same privileges, you add them to the sudo group using either usermod or gpasswd. After configuring sudo access, users can install development tools like VS Code or any other software requiring administrative privileges.

Enable the Root Account (Optional)

For most user management tasks, you do not need to enable the root account. Your existing sudo user can perform all necessary operations. However, if you prefer to work as root directly, you can set a root password.

Enabling root login creates an additional attack vector. If you enable root, use a strong, unique password and consider disabling root SSH access. For routine administration, using sudo from your regular account is the recommended approach.

Set a Root Password

To enable the root account, set a password using the passwd command with sudo privileges:

sudo passwd root

The system first prompts for your current user password to verify sudo access, then asks you to enter and confirm the new root password:

[sudo] password for youruser: 
New password: 
Retype new password: 
passwd: password updated successfully

After setting the root password, you can switch to root using the su command:

su -

The - flag starts a login shell with root’s environment variables. Enter the root password when prompted, and the terminal prompt changes to indicate root access:

Password: 
root@hostname:~#

To return to your regular user account, type exit or press Ctrl+D.

Create a New User Account

Before granting sudo access, you need a user account. If you are adding an existing user to sudo, skip to the next section. To create a new user, use the adduser command followed by the desired username:

sudo adduser josh

This command creates a home directory, copies default configuration files, and then prompts you to set a password and optional user information:

info: Adding user `josh' ...
info: Selecting UID/GID from range 1000 to 59999 ...
info: Adding new group `josh' (1001) ...
info: Adding new user `josh' (1001) with group `josh (1001)' ...
info: Creating home directory `/home/josh' ...
info: Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for josh
Enter the new value, or press ENTER for the default
	Full Name []: Josh User
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] Y
info: Adding new user `josh' to supplemental / extra groups `users' ...
info: Adding user `josh' to group `users' ...

Press Enter to skip the optional fields (Full Name, Room Number, etc.) if you do not need them. Type Y to confirm and complete the account creation.

The output format differs between Linux Mint versions. Mint 22 shows info: prefixes on each line, while Mint 21 uses a simpler format without prefixes. Both formats indicate successful user creation.

Verify the User Exists

Next, confirm the account was created by checking the password database:

grep josh /etc/passwd

A successful creation shows the user entry with their UID, home directory, and default shell:

josh:x:1001:1001:Josh User,,,:/home/josh:/bin/bash

Add User to the Sudo Group

Once the user account is ready, grant sudo privileges by adding them to the sudo group. Linux Mint provides two methods: usermod and gpasswd. Both achieve the same result.

Method 1: Using usermod (Recommended)

The usermod command modifies user account properties. The -aG flags append the user to a supplementary group without removing them from other groups:

sudo usermod -aG sudo josh

Always include the -a (append) flag when using usermod -G. Using -G alone replaces all supplementary groups, which can lock the user out of other group-based permissions.

Method 2: Using gpasswd

The gpasswd command manages group membership directly. The -a flag adds a user to the specified group:

sudo gpasswd -a josh sudo

When successful, the command confirms the addition:

Adding user josh to group sudo

Verify Sudo Group Membership

Next, confirm the user belongs to the sudo group using the id command:

id josh

The output lists all groups the user belongs to. Look for sudo in the groups list:

uid=1001(josh) gid=1001(josh) groups=1001(josh),27(sudo),100(users)

The 27(sudo) entry confirms the user has sudo group membership.

Test Sudo Privileges

Group membership changes take effect in new login sessions. The user must log out and log back in, or start a new shell session, before sudo works. To test without logging out, switch to the new user account:

su - josh

Enter the user’s password when prompted. Once logged in as the new user, verify sudo access by running a command that requires root privileges:

sudo whoami

The first time a user runs sudo, they see a brief warning about using root privileges responsibly. After entering their password, the command output confirms sudo works:

[sudo] password for josh: 
root

The output root confirms the user can execute commands as the root user. If you see a “not in the sudoers file” error instead, see the troubleshooting section below.

Add an Existing User to Sudo

If you already have a user account that needs sudo access, you do not need to recreate it. Add the existing user to the sudo group using either method:

sudo usermod -aG sudo existinguser

Alternatively, use gpasswd:

sudo gpasswd -a existinguser sudo

The user must start a new login session for the change to take effect. Running id existinguser immediately shows the new group, but the user’s current shell session does not recognize it until they log out and back in.

Remove Sudo Access from a User

To revoke sudo privileges, remove the user from the sudo group. Use gpasswd with the -d (delete) flag:

sudo gpasswd -d josh sudo

When successful, the command confirms removal:

Removing user josh from group sudo

Then verify the change with id josh. The sudo group should no longer appear in the output. Additionally, the user must log out and back in for the removal to take effect in their session.

Troubleshooting Common Issues

User Not in Sudoers File

If running a sudo command returns this error:

josh is not in the sudoers file. This incident will be reported.

This means the user is not in the sudo group or has not started a new session since being added. First, verify group membership from another account with sudo access:

id josh

If sudo does not appear in the groups list, add the user to the group:

sudo usermod -aG sudo josh

If the user is already in the sudo group, they need to log out completely and log back in. Switching users with su is not sufficient if the original login session predates the group change.

Authentication Failure with su

If switching to root with su returns “Authentication failure,” the root account either has no password set or the password is incorrect. By default, Linux Mint ships with root locked. To enable root access, set a password as described in the “Enable the Root Account” section above.

Sudo Asks for Root Password Instead of User Password

By default, sudo prompts for the current user’s password, not the root password. If sudo asks for the root password, the sudoers configuration may have been modified. Check that the sudo group has the correct permissions:

sudo grep '%sudo' /etc/sudoers

By default, the configuration should show:

%sudo   ALL=(ALL:ALL) ALL

This line grants all sudo group members full privileges using their own password. If the line is missing or modified, you may need to restore the default sudoers file from a backup or live USB.

Command Not Found After Using Sudo

Some commands available to your regular user may not be found when using sudo because sudo resets the PATH environment variable for security. To run commands from non-standard locations with sudo, provide the full path:

sudo /usr/local/bin/customcommand

Alternatively, use sudo -E to preserve your environment variables, though this has security implications and should be used sparingly.

Conclusion

You now have a user account with full sudo privileges on Linux Mint. The usermod -aG sudo command is the standard method for granting administrative access, while gpasswd provides an alternative syntax. For ongoing security, regularly audit which users have sudo access using grep sudo /etc/group and remove privileges from accounts that no longer require them. If you need to install a more capable terminal emulator or set up Git for version control, your new sudo user can now handle those installations.

Leave a Comment