To grant a user specific command permissions using sudo, you can edit the /etc/sudoers file with the visudo command. This allows you to specify which commands a user can run with sudo.
Steps to Grant Specific Command Permissions:
-
Open the sudoers file:
sudo visudo -
Add the specific command permission: Use the following syntax to grant a user permission to run a specific command:
username ALL=(ALL) /path/to/commandReplace
usernamewith the actual username and/path/to/commandwith the full path of the command you want to allow. -
Example: To allow a user named
bobto run theapt-get installcommand without needing a password, you would add:bob ALL=(ALL) NOPASSWD: /usr/bin/apt-get install -
Save and Exit: After making your changes, save the file and exit.
Important Notes:
-
Full Path: Always use the full path to the command to avoid ambiguity.
-
Multiple Commands: You can specify multiple commands by separating them with commas:
bob ALL=(ALL) NOPASSWD: /usr/bin/apt-get install, /usr/bin/apt-get remove -
Security: Be cautious when granting permissions to ensure you do not inadvertently give excessive privileges.
