The sudo command allows users to run administrative tasks and applications that they do not generally have permission to run. However, for this purpose they need to be given sudo privileges by the system administrator. sudo command allows admins to restrict users from performing sensitive tasks but give them temporary privilege of 15 minutes. When users run sudo command they don’t need to enter password for the next 15 minutes for their subsequent commands. It also makes things difficult for intruders to exploit system vulnerabilities. In this article, we will look at how to provide sudo access to user in Linux. You can use these steps in any Ubuntu/Debian system.
How to Provide Sudo Access to User in Linux
Here are the steps to give sudo privileges to user in Linux.
1. Log into Linux
You need to be able to log into your Linux system as root user or user with sudo privileges. Only such users can give sudo access to other users.
2. Create New User
Open terminal and run the following command to create new user. Replace new_user with a username of your choice.
$ sudo adduser new_user
The above command creates a new user, a group with that user as the owner and a home folder for the new user. You will be prompted for password for this user. Enter a secure password for this user.
You may be asked to enter additional information for the user such as name, phone number, etc. that are optional and can be skipped by pressing Enter.
3. Add New User to Sudo Group
By default, most Linux systems, especially Ubuntu/Debian systems have a sudo user group who have sudo privileges. To provide sudo privileges to new user, you need to add them to this sudo group with the following command. Again, replace new_user with the username that you have used in the previous step.
$ sudo usermod -aG sudo new_user
4. Verify new user’s group
At this point, your new user will have sudo privileges. You can verify it with the following command. It will list all the groups your user is a part of.
$ sudo groups new_user : new_user sudo
5. Verify sudo access
Switch to the new user with the following command.
$ su new_user
You will be prompted for password. Enter it and then you will be switched to new user’s account.
After that you will be able to run commands as usual.
$ ls /home
But sometimes, if you get ‘Access Denied’ error, you can use sudo command to overcome this issue.
$ sudo ls /home
If you try to access super sensitive contents like /root, you may even be asked for a password. At this point, enter the password you had set for your user.
In this article, we have learnt how to add sudo access for given user. For our example, we have created a new user and given it sudo privileges. You can do the same thing with an existing user also. The key is to remember that you need to add the user to sudo group. Once the user is added to this group, it automatically gets sudo privileges.
How to Kill Process Running on Specific Port
Sed Command to Delete Lines in Linux
How to Install & Use Wine in Linux
How to Iterate Over Multiple Lists in Parallel in Python
How to List All Files in Directory in Python