The sudo command allows users to perform tasks as another user - most commonly, the root user. Using sudo instead of su - has significant advantages. Most notably is that all operations performed with sudo are logged to /var/log/secure.
To use the sudo command, the user (in this article, the user is ned) must be added to the /etc/sudoers configuration file.
- At the user terminal, type:su -then press Enter. When prompted, type the root password then press Enter again. The terminal prompt will change from
$to#, indicating that you are now in a root terminal session. - At the root prompt, type:visudo then press Enter. The sudoers file will be displayed.
- Press the down arrow, until you locate: ## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL
- Uncomment: # %wheel ALL=(ALL) ALL by deleting the hash (#). The line should now look like:## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL
- Write your changes to the file by pressing: Esc (the Escape key) followed by :wq (that's ":"wq).
- Now press Enter. You will be returned to the root terminal.
- At the root terminal type: groups nedwhere ned is the username of the account that you are adding to sudoers. Press Enter. The result should be similar to:ned : nedThis indicates that the account ned belongs to the group ned.
- We will now add the account to the group wheel. Type:usermod -G ned,wheel nedthen press Enter.
It is important that you remember to add both groups (wheel and ned). - Now type: groups ned then press Enter. The result should be similar to:ned : ned wheelThis indicates that the account ned now belongs to the group ned and the group wheel. You can now run commands using
sudoinstead ofsu -.