ubuntu, updated

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

WhatCommand
Run one command as rootsudo apt update
Repeat the last command with sudosudo !!
Open a root shell (use sparingly)sudo -i
Run a command as another usersudo -u www-data whoami
Edit a root-owned file safelysudoedit /etc/hosts
What may I run with sudo?sudo -l
Forget the cached password nowsudo -k
Give a user admin rightssudo usermod -aG sudo USERNAME
Take admin rights awaysudo 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

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

§ home
~/knubertus/home/
1,1 Top