{
    "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 [--user username] PROGRAM [ARGUMENTS...]\n\n## DESCRIPTION\n\npkexec allows an authorized user to execute PROGRAM as another user. If username is not\nspecified, then the program will be 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- **REQUIRED AUTHORIZATIONS**\n- **EXAMPLE**\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 [--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": [
            "To specify what kind of authorization is needed to execute the program",
            "/usr/bin/pk-example-frobnicate as another user, simply write an action definition file like",
            "this",
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
            "<!DOCTYPE policyconfig PUBLIC",
            "\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"",
            "\"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd\">",
            "<policyconfig>",
            "<vendor>Examples for the PolicyKit Project</vendor>",
            "<vendorurl>http://hal.freedesktop.org/docs/PolicyKit/</vendorurl>",
            "<action id=\"org.freedesktop.policykit.example.pkexec.run-frobnicate\">",
            "<description>Run the PolicyKit example program Frobnicate</description>",
            "<description xml:lang=\"da\">Kør PolicyKit eksemplet Frobnicate</description>",
            "<message>Authentication is required to run the PolicyKit example program Frobnicate (user=$(user), program=$(program), commandline=$(commandline))</message>",
            "<message xml:lang=\"da\">Autorisering er påkrævet for at afvikle PolicyKit eksemplet Frobnicate (user=$(user), program=$(program), commandline=$(commandline))</message>",
            "<iconname>audio-x-generic</iconname>",
            "<defaults>",
            "<allowany>no</allowany>",
            "<allowinactive>no</allowinactive>",
            "<allowactive>authselfkeep</allowactive>",
            "</defaults>",
            "<annotate key=\"org.freedesktop.policykit.exec.path\">/usr/bin/pk-example-frobnicate</annotate>",
            "</action>",
            "</policyconfig>",
            "and drop it in the /usr/share/polkit-1/actions directory under a suitable name (e.g. matching",
            "the namespace of the action). Note that in addition to specifying the program, the",
            "authentication message, description, icon and defaults can be specified. Note that occurences",
            "of the strings $(user), $(program) and $(commandline) in the message will be replaced with",
            "respectively the user (of the form \"Real Name (username)\" or just \"username\" if there is no",
            "real name for the username), the binary to execute (a fully-qualified path, e.g.",
            "\"/usr/bin/pk-example-frobnicate\") and the command-line, e.g. \"pk-example-frobnicate foo bar\".",
            "For example, for the action defined above, the following authentication dialog will be shown:",
            "[IMAGE][2]",
            "+----------------------------------------------------------+",
            "|                     Authenticate                     [X] |",
            "+----------------------------------------------------------+",
            "|                                                          |",
            "|  [Icon]  Authentication is required to run the PolicyKit |",
            "|          example program Frobnicate                      |",
            "|                                                          |",
            "|          An application is attempting to perform an      |",
            "|          action that requires privileges. Authentication |",
            "|          is required to perform this action.             |",
            "|                                                          |",
            "|          Password: []  |",
            "|                                                          |",
            "| [V] Details:                                             |",
            "|  Command: /usr/bin/pk-example-frobnicate                 |",
            "|  Run As:  Super User (root)                              |",
            "|  Action:  org.fd.pk.example.pkexec.run-frobnicate        |",
            "|  Vendor:  Examples for the PolicyKit Project             |",
            "|                                                          |",
            "|                                  [Cancel] [Authenticate] |",
            "+----------------------------------------------------------+",
            "If the user is using the daDK locale, the dialog looks like this:",
            "[IMAGE][3]",
            "+----------------------------------------------------------+",
            "|                     Autorisering                     [X] |",
            "+----------------------------------------------------------+",
            "|                                                          |",
            "|  [Icon]  Autorisering er påkrævet for at afvikle         |",
            "|          PolicyKit eksemplet Frobnicate                  |",
            "|                                                          |",
            "|          Et program forsøger at udføre en handling der   |",
            "|          kræver privilegier. Autorisering er påkrævet.   |",
            "|                                                          |",
            "|          Kodeord: []  |",
            "|                                                          |",
            "| [V] Detaljer:                                            |",
            "|  Bruger:   Super User (root)                             |",
            "|  Program:  /usr/bin/pk-example-frobnicate                |",
            "|  Handling: org.fd.pk.example.pkexec.run-frobnicate       |",
            "|  Vendor:   Examples for the PolicyKit Project            |",
            "|                                                          |",
            "|                                [Annullér] [Autorisering] |",
            "+----------------------------------------------------------+",
            "Note that pkexec does no validation of the ARGUMENTS passed to PROGRAM. In the normal case",
            "(where administrator authentication is required every time pkexec is used), this is not a",
            "problem since if the user is an administrator he might as well just run pkexec bash to get",
            "root.",
            "However, if an action is used for which the user can retain authorization (or if the user is",
            "implicitly authorized), such as with pk-example-frobnicate above, this could be a security",
            "hole. Therefore, as a rule of thumb, programs for which the default required authorization is",
            "changed, should never implicitly trust user input (e.g. like any other well-written suid",
            "program)."
        ],
        "see_also": [
            {
                "name": "polkit",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/polkit/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": 3,
                "subsections": []
            },
            {
                "name": "RETURN VALUE",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "AUTHENTICATION AGENT",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SECURITY NOTES",
                "lines": 38,
                "subsections": []
            },
            {
                "name": "REQUIRED AUTHORIZATIONS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "EXAMPLE",
                "lines": 98,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 9,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "pkexec - Execute a command as another user\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "pkexec [--version] [--disable-internal-agent] [--help]\n\npkexec [--user username] PROGRAM [ARGUMENTS...]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "pkexec allows an authorized user to execute PROGRAM as another user. If username is not\nspecified, then the program will be 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 PolicyKit application, will use the authentication agent registered\nfor the calling process. However, if no authentication agent is available, then pkexec will\nregister its own textual authentication agent. This behavior can be turned off by passing the\n--disable-internal-agent option.\n",
                "subsections": []
            },
            "SECURITY NOTES": {
                "content": "Executing a program as another user is a privileged operation. By default the required\nauthorization (See the section called “REQUIRED 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\n[IMAGE][1]\n\n+----------------------------------------------------------+\n|                     Authenticate                     [X] |\n+----------------------------------------------------------+\n|                                                          |\n|  [Icon]  Authentication is needed to run `/bin/bash'     |\n|          as the super user                               |\n|                                                          |\n|          An application is attempting to perform an      |\n|          action that requires privileges. Authentication |\n|          as the super user is required to perform this   |\n|          action.                                         |\n|                                                          |\n|          Password for root: []  |\n|                                                          |\n| [V] Details:                                             |\n|  Command: /bin/bash                                      |\n|  Run As:  Super User (root)                              |\n|  Action:  org.freedesktop.policykit.exec                 |\n|  Vendor:  The PolicyKit Project                          |\n|                                                          |\n|                                  [Cancel] [Authenticate] |\n+----------------------------------------------------------+\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 allow you to run X11 applications as another user since the\n$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",
                "subsections": []
            },
            "REQUIRED AUTHORIZATIONS": {
                "content": "By default, the org.freedesktop.policykit.exec authorization is required unless an action\ndefinition file is present for the program in question. To require another authorization, it\ncan be specified using the org.freedesktop.policykit.exec.path annotation on an action (See\nthe section called “EXAMPLE” for details).\n",
                "subsections": []
            },
            "EXAMPLE": {
                "content": "To specify what kind of authorization is needed to execute the program\n/usr/bin/pk-example-frobnicate as another user, simply write an action definition file like\nthis\n\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE policyconfig PUBLIC\n\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"\n\"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd\">\n<policyconfig>\n\n<vendor>Examples for the PolicyKit Project</vendor>\n<vendorurl>http://hal.freedesktop.org/docs/PolicyKit/</vendorurl>\n\n<action id=\"org.freedesktop.policykit.example.pkexec.run-frobnicate\">\n<description>Run the PolicyKit example program Frobnicate</description>\n<description xml:lang=\"da\">Kør PolicyKit eksemplet Frobnicate</description>\n<message>Authentication is required to run the PolicyKit example program Frobnicate (user=$(user), program=$(program), commandline=$(commandline))</message>\n<message xml:lang=\"da\">Autorisering er påkrævet for at afvikle PolicyKit eksemplet Frobnicate (user=$(user), program=$(program), commandline=$(commandline))</message>\n<iconname>audio-x-generic</iconname>\n<defaults>\n<allowany>no</allowany>\n<allowinactive>no</allowinactive>\n<allowactive>authselfkeep</allowactive>\n</defaults>\n<annotate key=\"org.freedesktop.policykit.exec.path\">/usr/bin/pk-example-frobnicate</annotate>\n</action>\n\n</policyconfig>\n\nand drop it in the /usr/share/polkit-1/actions directory under a suitable name (e.g. matching\nthe namespace of the action). Note that in addition to specifying the program, the\nauthentication message, description, icon and defaults can be specified. Note that occurences\nof the strings $(user), $(program) and $(commandline) in the message will be replaced with\nrespectively the user (of the form \"Real Name (username)\" or just \"username\" if there is no\nreal name for the username), the binary to execute (a fully-qualified path, e.g.\n\"/usr/bin/pk-example-frobnicate\") and the command-line, e.g. \"pk-example-frobnicate foo bar\".\nFor example, for the action defined above, the following authentication dialog will be shown:\n\n[IMAGE][2]\n\n+----------------------------------------------------------+\n|                     Authenticate                     [X] |\n+----------------------------------------------------------+\n|                                                          |\n|  [Icon]  Authentication is required to run the PolicyKit |\n|          example program Frobnicate                      |\n|                                                          |\n|          An application is attempting to perform an      |\n|          action that requires privileges. Authentication |\n|          is required to perform this action.             |\n|                                                          |\n|          Password: []  |\n|                                                          |\n| [V] Details:                                             |\n|  Command: /usr/bin/pk-example-frobnicate                 |\n|  Run As:  Super User (root)                              |\n|  Action:  org.fd.pk.example.pkexec.run-frobnicate        |\n|  Vendor:  Examples for the PolicyKit Project             |\n|                                                          |\n|                                  [Cancel] [Authenticate] |\n+----------------------------------------------------------+\n\nIf the user is using the daDK locale, the dialog looks like this:\n\n[IMAGE][3]\n\n+----------------------------------------------------------+\n|                     Autorisering                     [X] |\n+----------------------------------------------------------+\n|                                                          |\n|  [Icon]  Autorisering er påkrævet for at afvikle         |\n|          PolicyKit eksemplet Frobnicate                  |\n|                                                          |\n|          Et program forsøger at udføre en handling der   |\n|          kræver privilegier. Autorisering er påkrævet.   |\n|                                                          |\n|          Kodeord: []  |\n|                                                          |\n| [V] Detaljer:                                            |\n|  Bruger:   Super User (root)                             |\n|  Program:  /usr/bin/pk-example-frobnicate                |\n|  Handling: org.fd.pk.example.pkexec.run-frobnicate       |\n|  Vendor:   Examples for the PolicyKit Project            |\n|                                                          |\n|                                [Annullér] [Autorisering] |\n+----------------------------------------------------------+\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), such as with pk-example-frobnicate above, this could be a security\nhole. Therefore, as a rule of thumb, programs for which the default required authorization is\nchanged, should never implicitly trust user input (e.g. like any other well-written suid\nprogram).\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 http://lists.freedesktop.org/mailman/listinfo/polkit-devel on how to subscribe.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "polkit(8), pkaction(1), pkcheck(1), pkttyagent(1)\n",
                "subsections": []
            },
            "NOTES": {
                "content": "1. /usr/share/gtk-doc/html/polkit-1/pkexec-bash.png\n\n2. /usr/share/gtk-doc/html/polkit-1/pkexec-frobnicate.png\n\n3. /usr/share/gtk-doc/html/polkit-1/pkexec-frobnicate-da.png\n\n\n\npolkit                                        May 2009                                     PKEXEC(1)",
                "subsections": []
            }
        }
    }
}