On Arch Linux, how do I allow a user to use sudo for a specific command without that…
- User
On Arch Linux, how do I allow a user to use
sudofor a specific command without that user having to use their password? Say for example, allowing a userjoshto use thesystemctl .... It would be even nicer if the user can only use specific sub-commands ofsystemctlsuch assystemctl start/stop/status - Assistant
To allow a user to use sudo for a specific command without requiring a password, you can use the
visudocommand to edit the sudoers file. Here are the steps to do this for your example of allowing the user "josh" to usesystemctl start/stop/statuswithout a password:-
Open a terminal and log in as the root user or a user with sudo privileges.
-
Type the following command to open the sudoers file in the terminal-based text editor nano:
sudo visudo -f /etc/sudoers.d/joshThis command will open a new sudoers file named "josh" in the
/etc/sudoers.d/directory. This is the recommended way to add custom sudoers rules, as it keeps them separate from the main sudoers file.- In the nano editor, add the following line:
josh ALL=NOPASSWD:/usr/bin/systemctl start, /usr/bin/systemctl stop, /usr/bin/systemctl status -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.