{
    "content": [
        {
            "type": "text",
            "text": "# pkexec (man)\n\n## NAME\n\npkexec - Execute a command as another user\n\n## SYNOPSIS\n\npkexec [--version] [--disable-internal-agent] [--help]\npkexec [--keep-cwd] [--user username] PROGRAM [ARGUMENTS...]\n\n## DESCRIPTION\n\npkexec allows an authorized user to execute PROGRAM as another user. If PROGRAM is not\nspecified, the default shell will be run. If username is not specified, then the program will\nbe executed as the administrative super user, root.\n\n## TLDR\n\n> Execute commands as another user.\n\n- Run command as root:\n  `pkexec {{command}}`\n- Switch user to root:\n  `pkexec`\n- Run command as a specific user:\n  `pkexec --user {{username}} {{command}}`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **RETURN VALUE**\n- **AUTHENTICATION AGENT**\n- **SECURITY NOTES**\n- **ACTION AND AUTHORIZATIONS**\n- **WRAPPER USAGE**\n- **VARIABLES**\n- **AUTHOR**\n- **BUGS**\n- **SEE ALSO**\n- **NOTES**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "pkexec",
        "section": "",
        "mode": "man",
        "summary": "pkexec - Execute a command as another user",
        "synopsis": "pkexec [--version] [--disable-internal-agent] [--help]\npkexec [--keep-cwd] [--user username] PROGRAM [ARGUMENTS...]",
        "tldr_summary": "Execute commands as another user.",
        "tldr_examples": [
            {
                "description": "Run command as root",
                "command": "pkexec {{command}}"
            },
            {
                "description": "Switch user to root",
                "command": "pkexec"
            },
            {
                "description": "Run command as a specific user",
                "command": "pkexec --user {{username}} {{command}}"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "polkit",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/polkit/8/json"
            },
            {
                "name": "polkitd",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/polkitd/8/json"
            },
            {
                "name": "pkaction",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/pkaction/1/json"
            },
            {
                "name": "pkcheck",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/pkcheck/1/json"
            },
            {
                "name": "pkttyagent",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/pkttyagent/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "RETURN VALUE",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "AUTHENTICATION AGENT",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SECURITY NOTES",
                "lines": 26,
                "subsections": []
            },
            {
                "name": "ACTION AND AUTHORIZATIONS",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "WRAPPER USAGE",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "VARIABLES",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 4,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "pkexec - Execute a command as another user\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "pkexec [--version] [--disable-internal-agent] [--help]\n\npkexec [--keep-cwd] [--user username] PROGRAM [ARGUMENTS...]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "pkexec allows an authorized user to execute PROGRAM as another user. If PROGRAM is not\nspecified, the default shell will be run. If username is not specified, then the program will\nbe executed as the administrative super user, root.\n",
                "subsections": []
            },
            "RETURN VALUE": {
                "content": "Upon successful completion, the return value is the return value of PROGRAM. If the calling\nprocess is not authorized or an authorization could not be obtained through authentication or\nan error occured, pkexec exits with a return value of 127. If the authorization could not be\nobtained because the user dismissed the authentication dialog, pkexec exits with a return\nvalue of 126.\n",
                "subsections": []
            },
            "AUTHENTICATION AGENT": {
                "content": "pkexec, like any other polkit application, will use the authentication agent registered for\nthe calling process or session. However, if no authentication agent is available, then pkexec\nwill register its own textual authentication agent. This behavior can be turned off by\npassing the --disable-internal-agent option.\n",
                "subsections": []
            },
            "SECURITY NOTES": {
                "content": "Executing a program as another user is a privileged operation. By default the action to check\nfor (see the section called “ACTION AND AUTHORIZATIONS”) requires administrator\nauthentication. In addition, the authentication dialog presented to the user will display the\nfull path to the program to be executed so the user is aware of what will happen.\n\nThe environment that PROGRAM will run it, will be set to a minimal known and safe environment\nin order to avoid injecting code through LDLIBRARYPATH or similar mechanisms. In addition\nthe PKEXECUID environment variable is set to the user id of the process invoking pkexec. As\na result, pkexec will not by default allow you to run X11 applications as another user since\nthe $DISPLAY and $XAUTHORITY environment variables are not set. These two variables will be\nretained if the org.freedesktop.policykit.exec.allowgui annotation on an action is set to a\nnonempty value; this is discouraged, though, and should only be used for legacy programs.\n\npkexec will run PROGRAM in username's home directory, unless --keep-cwd is used to override\nthis behavior\n\nNote that pkexec does no validation of the ARGUMENTS passed to PROGRAM. In the normal case\n(where administrator authentication is required every time pkexec is used), this is not a\nproblem since if the user is an administrator he might as well just run pkexec bash to get\nroot.\n\nHowever, if an action is used for which the user can retain authorization (or if the user is\nimplicitly authorized) this could be a security hole. Therefore, as a rule of thumb, programs\nfor which the default required authorization is changed, should never implicitly trust user\ninput (e.g. like any other well-written suid program).\n",
                "subsections": []
            },
            "ACTION AND AUTHORIZATIONS": {
                "content": "By default, the org.freedesktop.policykit.exec action is used. To use another action, use the\norg.freedesktop.policykit.exec.path annotation on an action with the value set to the full\npath of the program. In addition to specifying the program, the authentication message,\ndescription, icon and defaults can be specified. If the org.freedesktop.policykit.exec.argv1\nannotation is present, the action will only be picked if the first argument to the program\nmatches the value of the annotation.\n\nNote that authentication messages may reference variables (see the section called\n“VARIABLES”), for example $(user) will be expanded to the value of the user variable.\n",
                "subsections": []
            },
            "WRAPPER USAGE": {
                "content": "To avoid modifying existing software to prefix their command-line invocations with pkexec,\nit's possible to use pkexec in a \u001b[34mshe-bang wrapper[1] like this:\n\n#!/usr/bin/pkexec /usr/bin/python\n\nimport os\nimport sys\n\nprint \"Hello, I'm running as uid %d\"%(os.getuid())\n\nfor n in range(len(sys.argv)):\nprint \"arg[%d]=`%s'\"%(n, sys.argv[n])\n\nIf this script is installed into /usr/bin/my-pk-test, then the following annotations\n\n[...]\n<annotate key=\"org.freedesktop.policykit.exec.path\">/usr/bin/python</annotate>\n<annotate key=\"org.freedesktop.policykit.exec.argv1\">/usr/bin/my-pk-test</annotate>\n[...]\n\ncan be used to select the appropriate polkit action. Be careful to get the latter annotation\nright, otherwise it will match any pkexec invocation of /usr/bin/python scripts.\n",
                "subsections": []
            },
            "VARIABLES": {
                "content": "The following variables are set by pkexec. They can be used in authorization rules and\nmessages shown in authentication dialogs:\n\nprogram\nFully qualified path to the program to be executed. Example: “/bin/cat”\n\ncommandline\nThe requested command-line (do not use this for any security checks, it is not secure).\nExample: “cat /srv/xyz/foobar”\n\nuser\nThe user name of the user to execute the program as. Example: “davidz”\n\nuser.gecos\nThe full name of the user to execute the program as. Example: “David Zeuthen”\n\nuser.display\nA representation of the user to execute the program as that is suitable for display in an\nauthentication dialog. Is typically set to a combination of the user name and the full\nname. Example: “David Zeuthen (davidz)”\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Written by David Zeuthen <davidz@redhat.com> with a lot of help from many others.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Please send bug reports to either the distribution or the polkit-devel mailing list, see the\nlink \u001b[34mhttps://gitlab.freedesktop.org/polkit/polkit/-/issues/ on how to subscribe.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "polkit(8), polkitd(8), pkaction(1), pkcheck(1), pkttyagent(1)\n",
                "subsections": []
            },
            "NOTES": {
                "content": "1. she-bang wrapper\nhttp://en.wikipedia.org/wiki/Shebang(Unix)\n\npolkit                                        May 2009                                     PKEXEC(1)",
                "subsections": []
            }
        }
    }
}