In Linux, user management is a fundamental aspect of system administration, ensuring multiple users can securely and efficiently access the system. Among the various tasks involved in user management, creating new users and granting them appropriate permissions is crucial.
One of the most common requirements is to create a new user and provide them with the ability to execute commands with superuser privileges, also known as sudo access.
The sudo command in Linux allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. This is a powerful feature that enables users to perform administrative tasks without logging in as the root user, thereby enhancing security by limiting root access.
This guide is designed to help system administrators, and users granted administrative rights understand how to create a new user and configure sudo access for them. Whether setting up a new server, adding a new team member to your development environment, or simply enhancing your understanding of Linux user management, this step-by-step guide will walk you through the entire process!
Also Read: Install & Configure a CSF Firewall in a CenTOS Server
Steps to Create a New Sudo User
➔ Here, we will create an account for ‘Tech Support’ as an example.
useradd tech_support |
➔ Set the password for the new user.
passwd tech_support |
➔ The system will show a prompt where you can set and confirm a password for your new user account. If everything goes well, the system will say “all authentication tokens updated successfully.”
Steps to Add New User Directly to the sudoers File
➔ Open the ‘sudoers’ file with ‘visudo’, which ensures the file is edited safely.
sudo visudo |
➔ Add the following line at the end of the file, replacing the ‘tech_support’ with the actual username.
tech_support ALL=(ALL) ALL |
➔ Save the file and exit the editor. In nano, for example, you would press Ctrl+X, then ‘Y’, and ‘Enter’.
Test Sudo Privileges for the User Account
To ensure that the new user has the correct sudo privileges, perform the following test:
➔ Switch to the new user by entering this command.
su – tech_support |
➔ Run a command that requires superuser privileges. For example, try to list the root directory.
sudo ls /root |
If the user has sudo privileges, you will be prompted to enter the user’s password. After entering the password, the command should execute and display the contents of the root directory. If there are any errors, check the user’s group membership and the sudoers file configuration.
Also Read: Configure Windows Firewall to Allow Only Specific IPs For Port Connection
That’s it! You have now created a new user and granted them sudo privileges. This user can now perform administrative tasks with superuser rights by prefixing commands with sudo. Always use caution when granting sudo privileges, as it allows users to execute potentially harmful commands with elevated rights.