Linux "runuser" Command Line Options and Examples
run a command with substitute user and group ID

runuser allows to run commands with a substitute user and group ID. If the option -u is not given, it falls back to su-compatible semantics and a shell is executed. The difference between the commands runuser and su is that runuser does not ask for a password (because it may be executed by the root user only) and it uses a different PAM configuration.


Usage:

runuser [options] -u user [[--] command [argument...]]


    runuser [options] [-] [user [argument...]]






Command Line Options:

-c
Pass command to the shell with the -c option.
runuser -c ...
-f
Pass -f to the shell, which may or may not be useful depending on the shell.
runuser -f ...
-g
The primary group to be used. This option is allowed for the root user only.
runuser -g ...
-G
Specify a supplemental group. This option is available to the root user only. The first specifiedsupplementary group is also used as a primary group if the option --group is unspecified.
runuser -G ...
-
Start the shell as a login shell with an environment similar to a real login:o clears all the environment variables except for TERMo initializes the environment variables HOME, SHELL, USER, LOGNAME, PATHo changes to the target user's home directoryo sets argv[0] of the shell to '-' in order to make the shell a login shell
runuser - ...
-m
Preserve the entire environment, i.e. it does not set HOME, SHELL, USER nor LOGNAME. The option isignored if the option --login is specified.
runuser -m ...
-s
Run the specified shell instead of the default. The shell to run is selected according to the follow‐ing rules, in order:o the shell specified with --shello the shell specified in the environment variable SHELL if the --preserve-environment option isusedo the shell listed in the passwd entry of the target usero /bin/shIf the target user has a restricted shell (i.e. not listed in /etc/shells) the --shell option and theSHELL environment variables are ignored unless the calling user is root.
runuser -s ...
--session-command
Same as -c , but do not create a new session. (Discouraged.)
runuser --session-command ...
-V
Display version information and exit.
runuser -V ...
-h
Display help text and exit.CONFIG FILESrunuser reads the /etc/default/runuser and /etc/login.defs configuration files. The following configurationitems are relevant for runuser:ENV_PATH (string)Defines the PATH environment variable for a regular user. The default value is /usr/local/bin:/bin:/usr/bin.ENV_ROOTPATH (string)ENV_SUPATH (string)Defines the PATH environment variable for root. The default value is /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin.ALWAYS_SET_PATH (boolean)If set to yes and --login and --preserve-environment were not specified runuser initializes PATH.EXIT STATUSrunuser normally returns the exit status of the command it executed. If the command was killed by a signal,runuser returns the number of the signal plus 128.Exit status generated by runuser itself:1 Generic error before executing the requested command126 The requested command could not be executed127 The requested command was not foundFILES/etc/pam.d/runuserdefault PAM configuration file/etc/pam.d/runuser-lPAM configuration file if --login is specified/etc/default/runuserrunuser specific logindef config file/etc/login.defs global logindef config file
runuser -h ...