Who is sudo?
Root, sudo and why Ubuntu locks the root account. How to run commands as admin, give someone admin rights, and see who did what.
The short story
root is the superuser (user ID 0). It may do anything, including deleting the whole system.
sudo (“superuser do”) lets a normal user run one command as root. You type your own password, not root’s. Every call is logged.
On Ubuntu the root account has no password and you cannot log in as root. Admins are simply members of the group sudo. The first user created during installation is put there automatically.
Why this way? You work as a normal user, you only become root for the command that needs it, and the log shows who did it, not just “root”.
Note: Ubuntu 25.10 and newer ship
sudo-rs, a memory-safe rewrite. The commands on this page work the same.
Cheat sheet
| What | Command |
|---|---|
| Run one command as root | sudo apt update |
| Repeat the last command with sudo | sudo !! |
| Open a root shell (use sparingly) | sudo -i |
| Run a command as another user | sudo -u www-data whoami |
| Edit a root-owned file safely | sudoedit /etc/hosts |
| What may I run with sudo? | sudo -l |
| Forget the cached password now | sudo -k |
| Give a user admin rights | sudo usermod -aG sudo USERNAME |
| Take admin rights away | sudo deluser USERNAME sudo |
| Who has admin rights? | getent group sudo |
Group changes apply at the user’s next login.
The sudoers file
The rules live in /etc/sudoers and in files under /etc/sudoers.d/. Always edit them with visudo. It checks the syntax before saving. A typo in a plain editor can lock every admin out of sudo.
sudo visudo -f /etc/sudoers.d/backup
# user hosts=(run as) commands
backup ALL=(root) /usr/bin/rsync
%deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart myapp
%deploymeans the groupdeploy.NOPASSWD:skips the password. Only use it for narrow commands, never forALL.- Always use full paths to the command.
Who did what?
sudo journalctl _COMM=sudo --since today # all sudo calls today
sudo grep sudo /var/log/auth.log # same, classic log file
Gotchas
sudo echo "x" > /etc/filefails. The redirect>is done by your shell, not by root. Useecho "x" | sudo tee /etc/file(ortee -ato append).- After
usermod -aG sudo, the user must log out and in again. - Forgetting
-ainusermod -aGremoves the user from all other groups.