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:
This 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:
To grant permissions to a specific user, add a line in the following format:
Replace
username
with the actual username of the user you want to grant permissions to, and replacecommand
with 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
ifconfig
command. You would add the following line:This grants the user "john" the ability to run the
ifconfig
command with sudo.Save the changes and exit the text editor. In vi, you can press
Esc
to exit insert mode, then type:wq
and 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:
This 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:
To grant permission for a specific user to run any command with sudo, add a line in the following format:
Replace
username
with 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:
Save the changes and exit the text editor. In vi, you can press
Esc
to exit insert mode, then type:wq
and 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