visudo
Here's an example of how you can use visudo to grant permissions to a user:
Open a terminal window.
Type the following command and press Enter to open the sudoers file with visudo:
sudo visudoThis will prompt you to enter your password.
Once the sudoers file opens in the text editor, navigate to the section that defines user privileges. It typically starts with a line similar to:
# User privilege specificationTo grant permissions to a specific user, add a line in the following format:
username ALL=(ALL:ALL) commandReplace
usernamewith the actual username of the user you want to grant permissions to, and replacecommandwith the specific command or commands they should be able to execute with sudo.For example, let's say you want to grant the user "john" the ability to manage network settings using the
ifconfigcommand. You would add the following line:john ALL=(ALL:ALL) /sbin/ifconfigThis grants the user "john" the ability to run the
ifconfigcommand with sudo.Save the changes and exit the text editor. In vi, you can press
Escto exit insert mode, then type:wqand press Enter.Visudo will perform a syntax check, and if everything is valid, it will save the changes to the sudoers file.
Now, the user "john" should be able to execute the specified command with elevated privileges using the sudo command.
Grant ALL permissions to User
If you want to grant permission for a user to run any command with sudo, you can use the wildcard character ALL. Here's an example:
Open a terminal window.
Type the following command and press Enter to open the sudoers file with visudo:
sudo visudoThis will prompt you to enter your password.
Once the sudoers file opens in the text editor, navigate to the section that defines user privileges. It typically starts with a line similar to:
# User privilege specificationTo grant permission for a specific user to run any command with sudo, add a line in the following format:
username ALL=(ALL:ALL) ALLReplace
usernamewith the actual username of the user you want to grant permissions to.For example, if you want to grant the user "john" permission to run any command with sudo, you would add the following line:
john ALL=(ALL:ALL) ALLSave the changes and exit the text editor. In vi, you can press
Escto exit insert mode, then type:wqand press Enter.Visudo will perform a syntax check, and if everything is valid, it will save the changes to the sudoers file.
Now, the user "john" should have full sudo privileges and be able to execute any command with elevated privileges using the sudo command.
Last updated