Skip to content

su

12 commands

Switches to another user (root by default) in a new shell, optionally as a login shell or for a single command.

  • users
  • privilege

Install su

sudo apt install util-linux

Switching users7

su

Becomes root in the current environment after entering root’s password.

su -

A full root login shell: resets the environment and changes to /root. Usually what you want.

su - <user>

A login shell as another user.

Link
su -c "<command>" <user>

Runs one command as another user.

Link
su -s <shell> <user>

Uses a specific shell, needed for service accounts whose shell is /usr/sbin/nologin.

Link
su -p <user>

Keeps the current environment variables.

exit

Leaves the su shell and returns to your own user.

Compared with sudo3

sudo -i

A root login shell using your own password and sudo rights.

Link
sudo -u <user> <command>

Runs one command as another user via sudo.

Link
sudo -s

A root shell that keeps your environment.

Link

Auditing2

grep -E "su(\[|:)" /var/log/auth.log

Successful and failed su attempts on Debian and Ubuntu (/var/log/secure on RHEL).

Link
cat /etc/pam.d/su

PAM rules for su — for example, whether only the wheel group may use it.

Link