|SU(1)||General Commands Manual||SU(1)|
su — substitute
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
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,
PATH and the
umask(2) value are set
USER are set to
the target login and
PATH and the
umask(2) value are preserved.
TERM environment variable is always preserved.
The rest of the environment remains unmodified by default.
The options are as follows:
-loption is used. Useful to skip reading shell initialization files.
-apasswd”, provided for backwards compatibility.
suwill prompt for the password even when invoked by root.
USERare set to the default values for the target login.
PATHand the umask(2) value are set according to login.conf(5). Except for preserving
TERM, the rest of the environment is discarded.
-moption is specified.
options are mutually exclusive; the last one specified overrides any
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
option as understood by most shells. Note that
usually expects a single argument only; you have to quote it when passing
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
The following list provides the values of environment variables in
the new shell that is started by
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
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
su command first appeared in
Version 1 AT&T UNIX.
The login name is not optional for root if there are shell arguments.
|July 8, 2020||OpenBSD-6.8|