SU(1)

NAME
su - substitute user identity

SYNOPSIS
su [-fKLlm] [-a auth-type] [-c login-class] [-s login-shell] [login [shell arguments]]

DESCRIPTION
The su utility allows a user to run a shell with the user and group ID of another user without having to log out and in as that other user. All of the real, effective, and saved user and group IDs as well as all supplementary group IDs are always set according to the target user. If the target login name is not specified, “root” is used.

By default, the shell of the target login is invoked and the SHELL and HOME environment variables are set according to the target login, whereas the current working directory remains unchanged. If the target login has a user ID of 0, LOGNAME and USER are preserved and PATH and the umask(2) value are set according to login.conf(5); otherwise, LOGNAME and USER are set to the target login and PATH and the umask(2) value are preserved. The TERM environment variable is always preserved. The rest of the environment remains unmodified by default.

The options are as follows:

-   Same as the -l option (deprecated).

-a auth-type
    Specify an authentication type such as “skey” or “radius”.

-c login-class
    Specify a login class. You may only override the default class if you're already root.

-f  If the invoked shell is csh(1), this option prevents it from executing system or user startup files. For other shells, start a regular shell instead of a login shell when the -l option is used. Useful to skip reading shell initialization files.

-K  This is shorthand for “su -a passwd”, provided for backwards compatibility.

-L  Loop until a correct username and password combination is entered, similar to login(1). Note that in this mode target login must be specified explicitly, either on the command line or interactively. Additionally, su will prompt for the password even when invoked by root.

-l  Simulate a full login. The shell of the target login is invoked and the current working directory is changed to the home directory of the target login. HOME, SHELL, LOGNAME, and USER are set to the default values for the target login. PATH and the umask(2) value are set according to login.conf(5). Except for preserving TERM, the rest of the environment is discarded.

-m  Leave the environment unmodified. The login shell of the invoking user is started, and the current working directory is not changed. As a security precaution, if the target user's shell is a non-standard shell (as defined by getusershell(3)) and the caller's real UID is non-zero, su will fail.

-s login-shell
    Specify the path to an alternate login shell. You may only override the shell if you're already root. This option will override the shell even if the -m option is specified.

The -l and -m options are mutually exclusive; the last one specified overrides any previous ones.

If the optional shell arguments are provided on the command line, they are passed to the login shell of the target login. This allows it to pass arbitrary commands via the -c option as understood by most shells. Note that -c usually expects a single argument only; you have to quote it when passing multiple words.

If group 0 (normally “wheel”) has users listed then only those users can su to “root”. It is not sufficient to change a user's /etc/passwd entry to add them to the “wheel” group; they must explicitly be listed in /etc/group. If no one is in the “wheel” group, it is ignored, and anyone who knows the root password is permitted to su to “root”.

ENVIRONMENT
The following list provides the values of environment variables in the new shell that is started by su.

HOME
    The home directory of the target login, except that it remains unchanged with -m.

LOGNAME
    The target login by default, but unchanged if the target login has a UID of 0 or if -m is given.

PATH
    The search path. It remains unchanged by default, but is set according to the target login if the target login has a UID of 0 or if -l is given.

PWD The current working directory. It remains unchanged by default, but is set to the home directory of the target login with -l.

SHELL
    The new shell that is started. It is the shell of the target login by default, but the shell of the invoking user with -m.

TERM
    The terminal type. It is always retained from the invoking process.

USER
    Same as LOGNAME.

EXAMPLES
Run the command “makewhatis” as user “bin”. You will be asked for bin's password unless your real UID is 0.

    $ su bin -c makewhatis

Same as above, but the target command consists of more than a single word:

    $ su bin -c 'makewhatis /usr/local/man'

Same as above, but the target command is run with the resource limits of the login class “staff”. Note that the first -c option applies to su while the second is an argument to the shell.

    $ su -c staff bin -c 'makewhatis /usr/local/man'

Pretend a login for user “foo”:

    $ su -l foo

Same as above, but use S/Key for authentication:

    $ su -a skey -l foo

SEE ALSO
doas(1), login(1), setusercontext(3), group(5), login.conf(5), passwd(5), environ(7)

HISTORY
A su command first appeared in AT&T UNIX.

BUGS
The login name is not optional for root if there are shell arguments.