Lesson 4.3: Changing users: su and sudo
Why you work as an ordinary user, how sudo runs a single command as root (and logs it), sudo -l, -u and -i, why su to root fails on Ubuntu, and the principle of least privilege.
16 min
You will learn to
- Explain why daily work is done as an ordinary user
- Run single commands as root with sudo and see what you're allowed with sudo -l
- Open and leave a root shell with sudo -i and exit
- Run a command as another user with sudo -u
- Find sudo usage in /var/log/auth.log
Key terms
- Privilege
- The right to do something the system protects: read other users' files, install software, change settings.
- Principle of least privilege
- Give every user and program only the rights it needs, only for as long as it needs them.
- sudo
- Runs a single command as another user, root by default, after asking for your own password. Who may run what is set in /etc/sudoers, and every use is logged.
- su
- Starts a new shell as another user after asking for that user's password. su - also loads that user's login environment.
- Root shell
- A shell running as root, recognisable by the # prompt. Opened with sudo -i or sudo su -, closed with exit.
- Authentication log
- /var/log/auth.log: logins, failed passwords and every sudo command, with time, user and command.
← File and directory permissions · All lessons · Changing passwords →