{
    "content": [
        {
            "type": "text",
            "text": "# runuser (man)\n\n## NAME\n\nrunuser - run a command with substitute user and group ID\n\n## SYNOPSIS\n\nrunuser [options] -u user [[--] command [argument...]]\nrunuser [options] [-] [user [argument...]]\n\n## DESCRIPTION\n\nrunuser can be used to run commands with a substitute user and group ID. If the option -u is\nnot given, runuser falls back to su-compatible semantics and a shell is executed. The\ndifference between the commands runuser and su is that runuser does not ask for a password\n(because it may be executed by the root user only) and it uses a different PAM configuration.\nThe command runuser does not have to be installed with set-user-ID permissions.\n\n## TLDR\n\n> Run commands as a user and group without asking for password.\n\n- Run command as a different user:\n  `sudo runuser {{user}} {{-c|--command}} '{{command}}'`\n- Run command as a different user and group:\n  `sudo runuser {{user}} {{-g|--group}} {{group}} {{-c|--command}} '{{command}}'`\n- Start a login shell as a specific user:\n  `sudo runuser {{user}} {{-l|--login}}`\n- Specify a shell for running instead of the default shell (also works for login):\n  `sudo runuser {{user}} {{-s|--shell}} {{/bin/sh}}`\n- Preserve the entire environment of root (only if `--login` is not specified):\n  `sudo runuser {{user}} {{-p|--preserve-environment}} {{-c|--command}} '{{command}}'`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **OPTIONS** (10 subsections)\n- **CONFIG FILES** (3 subsections)\n- **EXIT STATUS**\n- **FILES**\n- **HISTORY**\n- **SEE ALSO**\n- **REPORTING BUGS**\n- **AVAILABILITY**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "runuser",
        "section": "",
        "mode": "man",
        "summary": "runuser - run a command with substitute user and group ID",
        "synopsis": "runuser [options] -u user [[--] command [argument...]]\nrunuser [options] [-] [user [argument...]]",
        "tldr_summary": "Run commands as a user and group without asking for password.",
        "tldr_examples": [
            {
                "description": "Run command as a different user",
                "command": "sudo runuser {{user}} {{-c|--command}} '{{command}}'"
            },
            {
                "description": "Run command as a different user and group",
                "command": "sudo runuser {{user}} {{-g|--group}} {{group}} {{-c|--command}} '{{command}}'"
            },
            {
                "description": "Start a login shell as a specific user",
                "command": "sudo runuser {{user}} {{-l|--login}}"
            },
            {
                "description": "Specify a shell for running instead of the default shell (also works for login)",
                "command": "sudo runuser {{user}} {{-s|--shell}} {{/bin/sh}}"
            },
            {
                "description": "Preserve the entire environment of root (only if `--login` is not specified)",
                "command": "sudo runuser {{user}} {{-p|--preserve-environment}} {{-c|--command}} '{{command}}'"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "-c",
                "long": "--command",
                "arg": null,
                "description": "Pass command to the shell with the -c option."
            },
            {
                "flag": "-f",
                "long": "--fast",
                "arg": null,
                "description": "Pass -f to the shell, which may or may not be useful, depending on the shell."
            },
            {
                "flag": "-g",
                "long": "--group",
                "arg": null,
                "description": "The primary group to be used. This option is allowed for the root user only."
            },
            {
                "flag": "-G",
                "long": "--supp-group",
                "arg": null,
                "description": "Specify a supplementary group. This option is available to the root user only. The first specified supplementary group is also used as a primary group if the option --group is not specified. -, -l, --login Start the shell as a login shell with an environment similar to a real login: • clears all the environment variables except for TERM and variables specified by --whitelist-environment • initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH • changes to the target user’s home directory • sets argv[0] of the shell to '-' in order to make the shell a login shell"
            },
            {
                "flag": "-P",
                "long": "--pty",
                "arg": null,
                "description": "Create a pseudo-terminal for the session. The independent terminal provides better security as the user does not share a terminal with the original session. This can be used to avoid TIOCSTI ioctl terminal injection and other security attacks against terminal file descriptors. The entire session can also be moved to the background (e.g., runuser --pty -u username —— command &). If the pseudo-terminal is enabled, then runuser works as a proxy between the sessions (copy stdin and stdout). This feature is mostly designed for interactive sessions. If the standard input is not a terminal, but for example a pipe (e.g., echo \"date\" | runuser --pty -u user), then the ECHO flag for the pseudo-terminal is disabled to avoid messy output."
            },
            {
                "flag": "-p",
                "long": "--preserve-environment",
                "arg": null,
                "description": "Preserve the entire environment, i.e., do not set HOME, SHELL, USER or LOGNAME. The option is ignored if the option --login is specified."
            },
            {
                "flag": "-s",
                "long": "--shell",
                "arg": null,
                "description": "Run the specified shell instead of the default. The shell to run is selected according to the following rules, in order: • the shell specified with --shell • the shell specified in the environment variable SHELL if the --preserve-environment option is used • the shell listed in the passwd entry of the target user • /bin/sh If the target user has a restricted shell (i.e., not listed in /etc/shells), then the --shell option and the SHELL environment variables are ignored unless the calling user is root. --session-command=command Same as -c, but do not create a new session. (Discouraged.)"
            },
            {
                "flag": "-w",
                "long": "--whitelist-environment",
                "arg": null,
                "description": "Don’t reset the environment variables specified in the comma-separated list when clearing the environment for --login. The whitelist is ignored for the environment variables HOME, SHELL, USER, LOGNAME, and PATH."
            },
            {
                "flag": "-V",
                "long": "--version",
                "arg": null,
                "description": "Display version information and exit."
            },
            {
                "flag": "-h",
                "long": "--help",
                "arg": null,
                "description": "Display help text and exit."
            }
        ],
        "examples": [],
        "see_also": [
            {
                "name": "setpriv",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/setpriv/1/json"
            },
            {
                "name": "su",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/su/1/json"
            },
            {
                "name": "login.defs",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/login.defs/5/json"
            },
            {
                "name": "shells",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/shells/5/json"
            },
            {
                "name": "pam",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/pam/8/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "-c --command",
                        "lines": 2,
                        "flag": "-c",
                        "long": "--command"
                    },
                    {
                        "name": "-f --fast",
                        "lines": 2,
                        "flag": "-f",
                        "long": "--fast"
                    },
                    {
                        "name": "-g --group",
                        "lines": 2,
                        "flag": "-g",
                        "long": "--group"
                    },
                    {
                        "name": "-G --supp-group",
                        "lines": 16,
                        "flag": "-G",
                        "long": "--supp-group"
                    },
                    {
                        "name": "-P --pty",
                        "lines": 11,
                        "flag": "-P",
                        "long": "--pty"
                    },
                    {
                        "name": "-m -p --preserve-environment",
                        "lines": 3,
                        "flag": "-p",
                        "long": "--preserve-environment"
                    },
                    {
                        "name": "-s --shell",
                        "lines": 19,
                        "flag": "-s",
                        "long": "--shell"
                    },
                    {
                        "name": "-w --whitelist-environment",
                        "lines": 4,
                        "flag": "-w",
                        "long": "--whitelist-environment"
                    },
                    {
                        "name": "-V --version",
                        "lines": 2,
                        "flag": "-V",
                        "long": "--version"
                    },
                    {
                        "name": "-h --help",
                        "lines": 2,
                        "flag": "-h",
                        "long": "--help"
                    }
                ]
            },
            {
                "name": "CONFIG FILES",
                "lines": 3,
                "subsections": [
                    {
                        "name": "ENV___PATH (string)",
                        "lines": 3
                    },
                    {
                        "name": "ENV___ROOTPATH (string), ENV___SUPATH (string)",
                        "lines": 3
                    },
                    {
                        "name": "ALWAYS___SET___PATH (boolean)",
                        "lines": 7
                    }
                ]
            },
            {
                "name": "EXIT STATUS",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "FILES",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "HISTORY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "REPORTING BUGS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AVAILABILITY",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "runuser - run a command with substitute user and group ID\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "runuser [options] -u user [[--] command [argument...]]\n\nrunuser [options] [-] [user [argument...]]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "runuser can be used to run commands with a substitute user and group ID. If the option -u is\nnot given, runuser falls back to su-compatible semantics and a shell is executed. The\ndifference between the commands runuser and su is that runuser does not ask for a password\n(because it may be executed by the root user only) and it uses a different PAM configuration.\nThe command runuser does not have to be installed with set-user-ID permissions.\n\nIf the PAM session is not required, then the recommended solution is to use the setpriv(1)\ncommand.\n\nWhen called without arguments, runuser defaults to running an interactive shell as root.\n\nFor backward compatibility, runuser defaults to not changing the current directory and to\nsetting only the environment variables HOME and SHELL (plus USER and LOGNAME if the target\nuser is not root). This version of runuser uses PAM for session management.\n\nNote that runuser in all cases use PAM (pamgetenvlist()) to do the final environment\nmodification. Command-line options such as --login and --preserve-environment affect the\nenvironment before it is modified by PAM.\n",
                "subsections": []
            },
            "OPTIONS": {
                "content": "",
                "subsections": [
                    {
                        "name": "-c --command",
                        "content": "Pass command to the shell with the -c option.\n",
                        "flag": "-c",
                        "long": "--command"
                    },
                    {
                        "name": "-f --fast",
                        "content": "Pass -f to the shell, which may or may not be useful, depending on the shell.\n",
                        "flag": "-f",
                        "long": "--fast"
                    },
                    {
                        "name": "-g --group",
                        "content": "The primary group to be used. This option is allowed for the root user only.\n",
                        "flag": "-g",
                        "long": "--group"
                    },
                    {
                        "name": "-G --supp-group",
                        "content": "Specify a supplementary group. This option is available to the root user only. The first\nspecified supplementary group is also used as a primary group if the option --group is\nnot specified.\n\n-, -l, --login\nStart the shell as a login shell with an environment similar to a real login:\n\n•   clears all the environment variables except for TERM and variables specified by\n--whitelist-environment\n\n•   initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH\n\n•   changes to the target user’s home directory\n\n•   sets argv[0] of the shell to '-' in order to make the shell a login shell\n",
                        "flag": "-G",
                        "long": "--supp-group"
                    },
                    {
                        "name": "-P --pty",
                        "content": "Create a pseudo-terminal for the session. The independent terminal provides better\nsecurity as the user does not share a terminal with the original session. This can be\nused to avoid TIOCSTI ioctl terminal injection and other security attacks against\nterminal file descriptors. The entire session can also be moved to the background (e.g.,\nrunuser --pty -u username —— command &). If the pseudo-terminal is enabled, then runuser\nworks as a proxy between the sessions (copy stdin and stdout).\n\nThis feature is mostly designed for interactive sessions. If the standard input is not a\nterminal, but for example a pipe (e.g., echo \"date\" | runuser --pty -u user), then the\nECHO flag for the pseudo-terminal is disabled to avoid messy output.\n",
                        "flag": "-P",
                        "long": "--pty"
                    },
                    {
                        "name": "-m -p --preserve-environment",
                        "content": "Preserve the entire environment, i.e., do not set HOME, SHELL, USER or LOGNAME. The\noption is ignored if the option --login is specified.\n",
                        "flag": "-p",
                        "long": "--preserve-environment"
                    },
                    {
                        "name": "-s --shell",
                        "content": "Run the specified shell instead of the default. The shell to run is selected according to\nthe following rules, in order:\n\n•   the shell specified with --shell\n\n•   the shell specified in the environment variable SHELL if the --preserve-environment\noption is used\n\n•   the shell listed in the passwd entry of the target user\n\n•   /bin/sh\n\nIf the target user has a restricted shell (i.e., not listed in /etc/shells), then the\n--shell option and the SHELL environment variables are ignored unless the calling\nuser is root.\n\n--session-command=command\nSame as -c, but do not create a new session. (Discouraged.)\n",
                        "flag": "-s",
                        "long": "--shell"
                    },
                    {
                        "name": "-w --whitelist-environment",
                        "content": "Don’t reset the environment variables specified in the comma-separated list when clearing\nthe environment for --login. The whitelist is ignored for the environment variables HOME,\nSHELL, USER, LOGNAME, and PATH.\n",
                        "flag": "-w",
                        "long": "--whitelist-environment"
                    },
                    {
                        "name": "-V --version",
                        "content": "Display version information and exit.\n",
                        "flag": "-V",
                        "long": "--version"
                    },
                    {
                        "name": "-h --help",
                        "content": "Display help text and exit.\n",
                        "flag": "-h",
                        "long": "--help"
                    }
                ]
            },
            "CONFIG FILES": {
                "content": "runuser reads the /etc/default/runuser and /etc/login.defs configuration files. The following\nconfiguration items are relevant for runuser:\n",
                "subsections": [
                    {
                        "name": "ENV___PATH (string)",
                        "content": "Defines the PATH environment variable for a regular user. The default value is\n/usr/local/bin:/bin:/usr/bin.\n"
                    },
                    {
                        "name": "ENV___ROOTPATH (string), ENV___SUPATH (string)",
                        "content": "Defines the PATH environment variable for root. ENVSUPATH takes precedence. The default\nvalue is /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin.\n"
                    },
                    {
                        "name": "ALWAYS___SET___PATH (boolean)",
                        "content": "If set to yes and --login and --preserve-environment were not specified runuser\ninitializes PATH.\n\nThe environment variable PATH may be different on systems where /bin and /sbin are merged\ninto /usr; this variable is also affected by the --login command-line option and the PAM\nsystem setting (e.g., pamenv(8)).\n"
                    }
                ]
            },
            "EXIT STATUS": {
                "content": "runuser normally returns the exit status of the command it executed. If the command was\nkilled by a signal, runuser returns the number of the signal plus 128.\n\nExit status generated by runuser itself:\n\n1\nGeneric error before executing the requested command\n\n126\nThe requested command could not be executed\n\n127\nThe requested command was not found\n",
                "subsections": []
            },
            "FILES": {
                "content": "/etc/pam.d/runuser\ndefault PAM configuration file\n\n/etc/pam.d/runuser-l\nPAM configuration file if --login is specified\n\n/etc/default/runuser\nrunuser specific logindef config file\n\n/etc/login.defs\nglobal logindef config file\n",
                "subsections": []
            },
            "HISTORY": {
                "content": "This runuser command was derived from coreutils' su, which was based on an implementation by\nDavid MacKenzie, and the Fedora runuser command by Dan Walsh.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "setpriv(1), su(1), login.defs(5), shells(5), pam(8)\n",
                "subsections": []
            },
            "REPORTING BUGS": {
                "content": "For bug reports, use the issue tracker at https://github.com/karelzak/util-linux/issues.\n",
                "subsections": []
            },
            "AVAILABILITY": {
                "content": "The runuser command is part of the util-linux package which can be downloaded from Linux\nKernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.\n\n\n\nutil-linux 2.37.2                            2021-06-02                                   RUNUSER(1)",
                "subsections": []
            }
        }
    }
}