How to use sudo and check your user

Overview

whoami prints the effective user. id shows user and group IDs. sudo runs an authorized command with elevated privileges, commonly as root.

Examples

whoami
id
groups
sudo apt update
sudo -k

How sudo behaves

  • Enter your own account password when prompted; typed characters are not displayed
  • sudo -v refreshes cached credentials
  • sudo -k invalidates cached credentials
  • Not every account is allowed to use sudo
  • Prefer sudo command over opening a persistent root shell

Safety

Administrator commands can alter or erase the entire system. Understand the command, arguments, and paths before approving it.

Never paste an unknown command into sudo. Routine work in your home directory should normally not require elevated access.