How to Create and Add Users to Sudoers on Linux Mint 22, 21 or 20

Managing user permissions and access levels is critical to Linux system administration. On Linux Mint 22, 21, or 20, you might need to create new users and grant them administrative privileges using the sudo command. This guide will walk you through creating a new user, adding them to the sudoers list, and resetting the root password if necessary. We will cover the use of commands like usermod and gpasswd to ensure proper user management and security.

Login to Root (su) on Linux Mint

Switching to the Root User

Begin creating and adding users to sudoers on Linux Mint, and start by switching to the root user. This is a necessary step for administrative tasks. Use the su command for this purpose. Note that the root account in Linux Mint doesn’t have a preset password. So, you’ll need to assign one.

Setting the Root Password

To set a root password, execute the following command in the terminal:

sudo passwd root

This command prompts you to enter your current sudo account password. Once verified, you can set a new password for the root user. Ensure that this password is strong and secure, as it provides extensive system access.

Add a New User to the Sudoers Group

Switching to Root User

Having established your root password, proceed to switch to the root user. This step is critical for performing administrative tasks, including adding a new user to the sudoers group.

Utilize the su command for this transition:

su

Upon execution, the system will prompt for the root password. Input the password you’ve set to continue. Successful entry will change your session to the root user, indicated by the username change in the terminal.

Create a New User Account on Linux Mint

Initiating User Creation

To add a new user account on Linux Mint, begin by determining the username for the new account. While modifying existing accounts is possible, this guide focuses on creating a fresh user account.

Executing the Adduser Command

Start by executing the adduser command followed by your chosen username. This command initiates the creation of a new user account. For instance:

adduser <desired_username>

For a practical example:

adduser josh

Upon running this command, the system prompts you to set a password for the new user. Using a strong password is crucial, especially for users with sudo privileges. A robust password typically includes uppercase and lowercase letters, symbols, numbers, and special characters.

Providing User Details

Next, the system asks for additional details about the new user. This information includes the user’s full name, room number, work phone, home phone, and other details. You can fill out these details or press Enter to skip each field.

Finalizing the User Creation

After inputting the details, confirm the correctness by typing “Y” and pressing Enter. This action completes the user creation process.

Verifying the New User

To ensure that the user account has been successfully added, check the /etc/passwd file. This can be done by executing the following command:

cat /etc/passwd

This command displays a list of all user accounts, where you can verify the addition of the new user.

Add New User to the Sudoers Group on Linux Mint

Granting Sudoers Access

After creating a new user or selecting an existing user, the next step involves granting them sudoers access. This is achieved through the usermod command, which modifies user properties.

Using the Usermod Command

Execute the following command to add a user to the sudoers group:

usermod -aG sudo <desired_username>

For instance, if the username is ‘josh’, the command would be:

usermod -aG sudo josh

Verifying Sudoers Group Membership

Confirming that the user has successfully been added to the sudoers group is essential. This verification ensures that the user has the necessary permissions to execute commands with sudo.

Executing the ID Command

Run the id command with the username to check group membership:

id <username>

Applying it to our example:

id josh

Alternative Method: Using gpasswd

As an alternative to usermod, the gpasswd command can also be used to add a user to the sudoers group.

Executing the Gpasswd Command

The command format is as follows:

gpasswd -a <example username> sudo

For example:

gpasswd -a josh sudo

Example output:

adding josh to group sudo

Confirm and Test the New Sudo User on Linux Mint

Switching to the New User Account

Having added your chosen user to the sudoers group, the next step is to test their new privileges. This is done by switching to the new user account using the su command.

Using the su Command

To switch to the new user account, execute:

su <example username>

For our example with ‘josh’:

su josh

Verifying Sudo Access

Once switched to the new user account, confirming their sudo privileges is crucial. This step ensures that the user has been correctly added to the sudoers group and has the necessary administrative access.

Executing Sudo Whoami

Run the following command to verify sudo access:

sudo whoami

This command prompts you to enter the sudo username and password for the account you are testing. Successful entry and execution will display ‘root’ as output, indicating that the user has adequate sudo privileges.

Conclusion

By following these steps, you can efficiently create new users and assign them sudo privileges on your Linux Mint system. Regularly managing and updating user permissions helps maintain system security and ensures that only authorized users have administrative access. Remember to keep your root password secure and update user privileges as needed to maintain a secure and well-managed system.

Leave a Comment