SU(1x) 1x SU(1x)

This manual page is part of Cross-Unix Documentation which is an attempt to provide documentation of similarities and (noteworthy) differencies between Unix-like systems. To be used as an addition to the POSIX standard.

suswitch user / become superuser

su [-plm] [-c command] [-s shell] [-] [username [shell arguments]]

The su utility is used to run a command or get a shell as another user, without having to log out. By default the environment is unmodified with the exception of LOGNAME, HOME, SHELL and USER. HOME and SHELL are set to the target user’s default values. LOGNAME and USER are set to the target user, unless the target user has a UID of 0 and -l was not specified, in which case it is unmodified. The invoked shell is the target user’s. This is the traditional behaviour of su. If not using -m and the target login has a UID of 0 then the PATH variable and umask are set to implementation defined behaviour.

If [username] was not set it defaults to UID 0 (also known as Super-User).

-, -l
Simulate a full login, this discards the origin user’s environment, expect for few implementation defined ones (like TERM ). Absent in BusyBox.
command
Executes command as the target user. This flag is used for "login class" in NetBSD, FreeBSD and OpenBSD, where you must pass the command by appending it to the end, along with the target user’s username.
, -m
Preserve the environment, few exceptions are present between implementations. GNU: preserve expect for PATH and IFS
shell
Login to target user with shell instead of their default one. This is absent in NetBSD and in FreeBSD is used to specify that the “MAC label” must be set and takes no argument.
[shell arguments]
Executes the remaining [shell arguments] in the target user's shell non-interactively. This seems to be absent in Busybox.

GNU coreutils 8.30, Busybox 1.30.1, OpenBSD 6.4, NetBSD 8.0, FreeBSD 12.0

doas(1), login(1), sudo(1), environ(7)

A su command appeared in Version 7 AT&T UNIX.

Haelwenn (lanodan) Monnier <contact+c-u-d@hacktivis.me>

2019-03-06 Linux 6.12.21-gentoo-x86_64