manpagez: man pages & more
info coreutils
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

22.5 su: Run a command with substitute user and group ID

su allows one user to temporarily become another user. It runs a command (often an interactive shell) with the real and effective user ID, group ID, and supplemental groups of a given user. Synopsis:

su [option]… [user [arg]…]

If no user is given, the default is root, the super-user. The shell to use is taken from user's passwd entry, or ‘/bin/sh’ if none is specified there. If user has a password, su prompts for the password unless run by a user with effective user ID of zero (the super-user).

By default, su does not change the current directory. It sets the environment variables HOME and SHELL from the password entry for user, and if user is not the super-user, sets USER and LOGNAME to user. By default, the shell is not a login shell.

Any additional args are passed as additional arguments to the shell.

GNU su does not treat ‘/bin/sh’ or any other shells specially (e.g., by setting argv[0] to ‘-su’, passing ‘-c’ only to certain shells, etc.).

su can optionally be compiled to use syslog to report failed, and optionally successful, su attempts. (If the system supports syslog.) However, GNU su does not check if the user is a member of the wheel group; see below.

The program accepts the following options. Also see Common options.

-c command

Pass command, a single command line to run, to the shell with a ‘-c’ option instead of starting an interactive shell.


Pass the ‘-f’ option to the shell. This probably only makes sense if the shell run is csh or tcsh, for which the ‘-f’ option prevents reading the startup file (‘.cshrc’). With Bourne-like shells, the ‘-f’ option disables file name pattern expansion (globbing), which is not likely to be useful.


Make the shell a login shell. This means the following. Unset all environment variables except TERM, HOME, and SHELL (which are set as described above), and USER and LOGNAME (which are set, even for the super-user, as described above), and set PATH to a compiled-in default value. Change to user's home directory. Prepend ‘-’ to the shell's name, intended to make it read its login startup file(s).


Do not change the environment variables HOME, USER, LOGNAME, or SHELL. Run the shell given in the environment variable SHELL instead of the shell from user's passwd entry, unless the user running su is not the super-user and user's shell is restricted. A restricted shell is one that is not listed in the file ‘/etc/shells’, or in a compiled-in list if that file does not exist. Parts of what this option does can be overridden by ‘--login’ and ‘--shell’.

-s shell

Run shell instead of the shell from user's passwd entry, unless the user running su is not the super-user and user's shell is restricted (see ‘-m’ just above).

Exit status:

1   if su itself fails
126 if subshell is found but cannot be invoked
127 if subshell cannot be found
the exit status of the subshell otherwise

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© 2000-2021
Individual documents may contain additional copyright information.