sudo — running commands as another user
cheat sheet · Ubuntu 24.04 · sudo 1.9 https://lab.dimsanych.ru/en/wiki/sudo/Cheat sheet
-
sudo apt updaterun a command as root -
sudo -u postgres psqlrun as another user -
sudo -iinteractive root shell -
sudo -lwhat I'm allowed to run -
sudoedit /etc/nginx/nginx.confsafely edit a root-owned file -
sudo visudo -f /etc/sudoers.d/10-xedit sudoers rules
Options
sudoers
Rights come from membership in the sudo group (Ubuntu) / wheel
(RHEL), or an explicit rule. Never edit sudoers directly — only
through visudo (it checks syntax, otherwise you can lock yourself out
of sudo):
Rule format and aliases:
NOPASSWD: — no password prompt (for automation; keep the scope narrow!).
Options and sudoedit
Useful Defaults (in /etc/sudoers.d/):
sudoedit edits a copy under your own name and atomically puts it back —
safer than sudo vim (which never runs the editor as root).