Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| system:linux:config:sudo [2026/01/26 20:37] – removed - external edit (Unknown date) 127.0.0.1 | system:linux:config:sudo [2026/02/01 21:08] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Linux : Sudo and Sudoers ====== | ||
| + | **sudo** stands for " | ||
| + | |||
| + | ===== Usage ===== | ||
| + | |||
| + | <code bash> | ||
| + | ilyasa@sandbox: | ||
| + | </ | ||
| + | |||
| + | This is equivalent to running: | ||
| + | |||
| + | <code bash> | ||
| + | ilyasa@sandbox: | ||
| + | root@sandbox: | ||
| + | </ | ||
| + | |||
| + | ===== Adding a User to Sudoers ===== | ||
| + | The **sudoers** file determines which users are allowed to use the sudo command and what commands they can execute. | ||
| + | |||
| + | By default, sudo creates a group that is granted full root access. | ||
| + | |||
| + | * The **sudo** group is common on Debian-based distributions. | ||
| + | * The **wheel** group is common on Red Hat/ | ||
| + | |||
| + | To add a user to the sudoers list, you can add them to one of those groups: | ||
| + | |||
| + | <code bash> | ||
| + | usermod -a -G sudo < | ||
| + | # Or | ||
| + | usermod -a -G wheel < | ||
| + | </ | ||
| + | |||
| + | ===== Sudoers File Configuration ===== | ||
| + | The file < | ||
| + | |||
| + | Here is the default configuration on an Ubuntu system: | ||
| + | |||
| + | < | ||
| + | # User privilege specification | ||
| + | root ALL=(ALL: | ||
| + | |||
| + | # Members of the admin group may gain root privileges | ||
| + | %admin ALL=(ALL) ALL | ||
| + | |||
| + | # Allow members of group sudo to execute any command | ||
| + | %sudo | ||
| + | </ | ||
| + | |||
| + | Explanation: | ||
| + | * **ALL=** : The user can run commands on all hosts. | ||
| + | * **(ALL: | ||
| + | * **ALL** : The user can execute any command. | ||
| + | * **%** : Indicates a group configuration. | ||
| + | |||
| + | ===== Custom Configuration Example ===== | ||
| + | < | ||
| + | %admin ALL=(ALL) NOPASSWD: / | ||
| + | </ | ||
| + | |||
| + | Explanation: | ||
| + | * **NOPASSWD** : The user will not be prompted for a password when running the command. | ||
| + | * **/ | ||
| + | |||
| + | <WRAP info> | ||
| + | It is recommended to use **visudo** when editing the **/ | ||
| + | </ | ||
| + | |||
| + | ==== Example ==== | ||
| + | |||
| + | <code bash> | ||
| + | sudo visudo -f / | ||
| + | </ | ||
| + | |||
| + | <code conf> | ||
| + | # Allow members of the admin group to run apt and systemctl commands without a password | ||
| + | %admin ALL=(ALL) NOPASSWD: / | ||
| + | </ | ||