In Linux, granting sudo privileges to a user allows them to perform administrative tasks. This guide will show you how to do this in a simple and clear way. We will also provide a working example and a test scenario to ensure everything works as expected.
Understanding Sudo Privileges
Sudo (superuser do) allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. Granting sudo privileges means giving a user the ability to execute these commands.
Steps to Grant Sudo Privileges
Follow these steps to grant sudo privileges to a user:
- Log in as Root or a User with Sudo Privileges: First, you need to log in as the root user or a user who already has sudo privileges.
- Add the User: If the user does not already exist, you can add a new user with the following command. Replace
username
with the actual username you want to create.sudo adduser [username]
- Grant Sudo Privileges: Add the user to the sudo group with this command:
sudo usermod -aG sudo [username]
This command modifies the user and adds them to the sudo group, giving them sudo privileges.
Look into the sudoers file using visudo
. You will find an entry like %sudo ALL=(ALL:ALL) ALL
. Here, %sudo
refers to the sudo group.
Example: Granting Sudo Privileges
Let’s go through an example. We will create a user named tecadmin
and grant them sudo privileges.
- Create the User: Use the following command to create a user named tecadmin in your system. You can change name as per your requirements.
sudo adduser tecadmin
Follow the prompts to set the user’s password and other details.
- Grant Sudo Privileges: This command will add newly created user tecadmin to the “sudo” group. This group is available in your system by default with all sudo privileges.
sudo usermod -aG sudo tecadmin
- Switch to the User: To ensure the user has been granted sudo privileges, switch to the account.
su - tecadmin
This command switches you to the user
tecadmin
. - Run a Sudo Command:
sudo ls /root
If
tecadmin
has sudo privileges, you should be able to list the contents of the root directory. You will be prompted to entertecadmin
‘s password to confirm the command.
![Linux: Setup Sudo Permissions for User](https://tecadmin.net/wp-content/uploads/2024/06/setup-sudo-priviledges-in-linux.png)
Conclusion
Granting sudo privileges to a user in Linux is a straightforward process. By following this guide, you can easily manage user permissions and ensure your system is both secure and flexible. Remember to always verify the changes by testing the user’s sudo access.
2 Comments
Hi! Would you mind if I share your blog with my facebook group?
There’s a lot of folks that I think would really appreciate
your content. Please let me know. Thank you
Heya i am for the first time here. I came across this board and I find It really useful & it helped
me out a lot. I hope to give something back and help
others like you aided me.