{
    "mode": "man",
    "parameter": "sudo",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/man/sudo/json",
    "generated": "2026-06-05T19:40:27Z",
    "synopsis": "sudo -h | -K | -k | -V\nsudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]\nsudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]\nsudo [-ABbEHnPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory]\n[-r role] [-t type] [-T timeout] [-u user] [VAR=value] [-i | -s] [command]\nsudoedit [-ABknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory]\n[-r role] [-t type] [-T timeout] [-u user] file ...",
    "sections": {
        "NAME": {
            "content": "sudo, sudoedit — execute a command as another user\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "sudo -h | -K | -k | -V\nsudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]\nsudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]\nsudo [-ABbEHnPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory]\n[-r role] [-t type] [-T timeout] [-u user] [VAR=value] [-i | -s] [command]\nsudoedit [-ABknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory]\n[-r role] [-t type] [-T timeout] [-u user] file ...\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "sudo allows a permitted user to execute a command as the superuser or another user, as speci‐\nfied by the security policy.  The invoking user's real (not effective) user-ID is used to de‐\ntermine the user name with which to query the security policy.\n\nsudo supports a plugin architecture for security policies, auditing, and input/output logging.\nThird parties can develop and distribute their own plugins to work seamlessly with the sudo\nfront-end.  The default security policy is sudoers, which is configured via the file\n/etc/sudoers, or via LDAP.  See the Plugins section for more information.\n\nThe security policy determines what privileges, if any, a user has to run sudo.  The policy may\nrequire that users authenticate themselves with a password or another authentication mechanism.\nIf authentication is required, sudo will exit if the user's password is not entered within a\nconfigurable time limit.  This limit is policy-specific; the default password prompt timeout\nfor the sudoers security policy is 0 minutes.\n\nSecurity policies may support credential caching to allow the user to run sudo again for a pe‐\nriod of time without requiring authentication.  By default, the sudoers policy caches creden‐\ntials on a per-terminal basis for 15 minutes.  See the timestamptype and timestamptimeout op‐\ntions in sudoers(5) for more information.  By running sudo with the -v option, a user can up‐\ndate the cached credentials without running a command.\n\nOn systems where sudo is the primary method of gaining superuser privileges, it is imperative\nto avoid syntax errors in the security policy configuration files.  For the default security\npolicy, sudoers(5), changes to the configuration files should be made using the visudo(8) util‐\nity which will ensure that no syntax errors are introduced.\n\nWhen invoked as sudoedit, the -e option (described below), is implied.\n\nSecurity policies and audit plugins may log successful and failed attempts to run sudo.  If an\nI/O plugin is configured, the running command's input and output may be logged as well.\n\nThe options are as follows:\n",
            "subsections": [
                {
                    "name": "-A --askpass",
                    "content": "Normally, if sudo requires a password, it will read it from the user's terminal.\nIf the -A (askpass) option is specified, a (possibly graphical) helper program is\nexecuted to read the user's password and output the password to the standard out‐\nput.  If the SUDOASKPASS environment variable is set, it specifies the path to the\nhelper program.  Otherwise, if sudo.conf(5) contains a line specifying the askpass\nprogram, that value will be used.  For example:\n\n# Path to askpass helper program\nPath askpass /usr/X11R6/bin/ssh-askpass\n\nIf no askpass program is available, sudo will exit with an error.\n",
                    "flag": "-A",
                    "long": "--askpass"
                },
                {
                    "name": "-B --bell",
                    "content": "tion has no effect if an askpass program is used.\n",
                    "flag": "-B",
                    "long": "--bell"
                },
                {
                    "name": "-b --background",
                    "content": "Run the given command in the background.  Note that it is not possible to use shell\njob control to manipulate background processes started by sudo.  Most interactive\ncommands will fail to work properly in background mode.\n",
                    "flag": "-b",
                    "long": "--background"
                },
                {
                    "name": "-C --close-from",
                    "content": "Close all file descriptors greater than or equal to num before executing a command.\nValues less than three are not permitted.  By default, sudo will close all open\nfile descriptors other than standard input, standard output, and standard error\nwhen executing a command.  The security policy may restrict the user's ability to\nuse this option.  The sudoers policy only permits use of the -C option when the ad‐\nministrator has enabled the closefromoverride option.\n",
                    "flag": "-C",
                    "long": "--close-from"
                },
                {
                    "name": "-D --chdir",
                    "content": "Run the command in the specified directory instead of the current working direc‐\ntory.  The security policy may return an error if the user does not have permission\nto specify the working directory.\n",
                    "flag": "-D",
                    "long": "--chdir"
                },
                {
                    "name": "-E --preserve-env",
                    "content": "Indicates to the security policy that the user wishes to preserve their existing\nenvironment variables.  The security policy may return an error if the user does\nnot have permission to preserve the environment.\n",
                    "flag": "-E",
                    "long": "--preserve-env"
                },
                {
                    "name": "--preserve-env=list",
                    "content": "Indicates to the security policy that the user wishes to add the comma-separated\nlist of environment variables to those preserved from the user's environment.  The\nsecurity policy may return an error if the user does not have permission to pre‐\nserve the environment.  This option may be specified multiple times.\n",
                    "long": "--preserve-env",
                    "arg": "list"
                },
                {
                    "name": "-e --edit",
                    "content": "string \"sudoedit\" is used when consulting the security policy.  If the user is au‐\nthorized by the policy, the following steps are taken:\n\n1.   Temporary copies are made of the files to be edited with the owner set to the\ninvoking user.\n\n2.   The editor specified by the policy is run to edit the temporary files.  The\nsudoers policy uses the SUDOEDITOR, VISUAL and EDITOR environment variables\n(in that order).  If none of SUDOEDITOR, VISUAL or EDITOR are set, the first\nprogram listed in the editor sudoers(5) option is used.\n\n3.   If they have been modified, the temporary files are copied back to their orig‐\ninal location and the temporary versions are removed.\n\nTo help prevent the editing of unauthorized files, the following restrictions are\nenforced unless explicitly allowed by the security policy:\n\n••  Symbolic links may not be edited (version 1.8.15 and higher).\n\n••  Symbolic links along the path to be edited are not followed when the parent di‐\nrectory is writable by the invoking user unless that user is root (version\n1.8.16 and higher).\n\n••  Files located in a directory that is writable by the invoking user may not be\nedited unless that user is root (version 1.8.16 and higher).\n\nUsers are never allowed to edit device special files.\n\nIf the specified file does not exist, it will be created.  Note that unlike most\ncommands run by sudo, the editor is run with the invoking user's environment unmod‐\nified.  If the temporary file becomes empty after editing, the user will be\nprompted before it is installed.  If, for some reason, sudo is unable to update a\nfile with its edited version, the user will receive a warning and the edited copy\nwill remain in a temporary file.\n",
                    "flag": "-e",
                    "long": "--edit"
                },
                {
                    "name": "-g --group",
                    "content": "Run the command with the primary group set to group instead of the primary group\nspecified by the target user's password database entry.  The group may be either a\ngroup name or a numeric group-ID (GID) prefixed with the ‘#’ character (e.g., #0\nfor GID 0).  When running a command as a GID, many shells require that the ‘#’ be\nescaped with a backslash (‘\\’).  If no -u option is specified, the command will be\nrun as the invoking user.  In either case, the primary group will be set to group.\nThe sudoers policy permits any of the target user's groups to be specified via the\n-g option as long as the -P option is not in use.\n",
                    "flag": "-g",
                    "long": "--group"
                },
                {
                    "name": "-H --set-home",
                    "content": "Request that the security policy set the HOME environment variable to the home di‐\nrectory specified by the target user's password database entry.  Depending on the\npolicy, this may be the default behavior.\n",
                    "flag": "-H",
                    "long": "--set-home"
                },
                {
                    "name": "-h --help",
                    "content": "",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-h --host",
                    "content": "Run the command on the specified host if the security policy plugin supports remote\ncommands.  Note that the sudoers plugin does not currently support running remote\ncommands.  This may also be used in conjunction with the -l option to list a user's\nprivileges for the remote host.\n",
                    "flag": "-h",
                    "long": "--host"
                },
                {
                    "name": "-i --login",
                    "content": "Run the shell specified by the target user's password database entry as a login\nshell.  This means that login-specific resource files such as .profile,\n.bashprofile, or .login will be read by the shell.  If a command is specified, it\nis passed to the shell as a simple command using the -c option.  The command and\nany arguments are concatenated, separated by spaces, after escaping each character\n(including white space) with a backslash (‘\\’) except for alphanumerics, under‐\nscores, hyphens, and dollar signs.  If no command is specified, an interactive\nshell is executed.  sudo attempts to change to that user's home directory before\nrunning the shell.  The command is run with an environment similar to the one a\nuser would receive at log in.  Note that most shells behave differently when a com‐\nmand is specified as compared to an interactive session; consult the shell's manual\nfor details.  The Command environment section in the sudoers(5) manual documents\nhow the -i option affects the environment in which a command is run when the\nsudoers policy is in use.\n",
                    "flag": "-i",
                    "long": "--login"
                },
                {
                    "name": "-K --remove-timestamp",
                    "content": "Similar to the -k option, except that it removes the user's cached credentials en‐\ntirely and may not be used in conjunction with a command or other option.  This op‐\ntion does not require a password.  Not all security policies support credential\ncaching.\n",
                    "flag": "-K",
                    "long": "--remove-timestamp"
                },
                {
                    "name": "-k --reset-timestamp",
                    "content": "When used without a command, invalidates the user's cached credentials.  In other\nwords, the next time sudo is run a password will be required.  This option does not\nrequire a password, and was added to allow a user to revoke sudo permissions from a\n.logout file.\n\nWhen used in conjunction with a command or an option that may require a password,\nthis option will cause sudo to ignore the user's cached credentials.  As a result,\nsudo will prompt for a password (if one is required by the security policy) and\nwill not update the user's cached credentials.\n\nNot all security policies support credential caching.\n",
                    "flag": "-k",
                    "long": "--reset-timestamp"
                },
                {
                    "name": "-l --list",
                    "content": "voking user (or the user specified by the -U option) on the current host.  A longer\nlist format is used if this option is specified multiple times and the security\npolicy supports a verbose output format.\n\nIf a command is specified and is permitted by the security policy, the fully-quali‐\nfied path to the command is displayed along with any command line arguments.  If a\ncommand is specified but not allowed by the policy, sudo will exit with a status\nvalue of 1.\n",
                    "flag": "-l",
                    "long": "--list"
                },
                {
                    "name": "-n --non-interactive",
                    "content": "Avoid prompting the user for input of any kind.  If a password is required for the\ncommand to run, sudo will display an error message and exit.\n",
                    "flag": "-n",
                    "long": "--non-interactive"
                },
                {
                    "name": "-P --preserve-groups",
                    "content": "Preserve the invoking user's group vector unaltered.  By default, the sudoers pol‐\nicy will initialize the group vector to the list of groups the target user is a\nmember of.  The real and effective group-IDs, however, are still set to match the\ntarget user.\n",
                    "flag": "-P",
                    "long": "--preserve-groups"
                },
                {
                    "name": "-p --prompt",
                    "content": "Use a custom password prompt with optional escape sequences.  The following percent\n(‘%’) escape sequences are supported by the sudoers policy:\n\n%H  expanded to the host name including the domain name (only if the machine's host\nname is fully qualified or the fqdn option is set in sudoers(5))\n\n%h  expanded to the local host name without the domain name\n\n%p  expanded to the name of the user whose password is being requested (respects\nthe rootpw, targetpw, and runaspw flags in sudoers(5))\n\n%U  expanded to the login name of the user the command will be run as (defaults to\nroot unless the -u option is also specified)\n\n%u  expanded to the invoking user's login name\n\n%%  two consecutive ‘%’ characters are collapsed into a single ‘%’ character\n\nThe custom prompt will override the default prompt specified by either the security\npolicy or the SUDOPROMPT environment variable.  On systems that use PAM, the cus‐\ntom prompt will also override the prompt specified by a PAM module unless the\npasspromptoverride flag is disabled in sudoers.\n",
                    "flag": "-p",
                    "long": "--prompt"
                },
                {
                    "name": "-R --chroot",
                    "content": "Change to the specified root directory (see chroot(8)) before running the command.\nThe security policy may return an error if the user does not have permission to\nspecify the root directory.\n",
                    "flag": "-R",
                    "long": "--chroot"
                },
                {
                    "name": "-r --role",
                    "content": "Run the command with an SELinux security context that includes the specified role.\n",
                    "flag": "-r",
                    "long": "--role"
                },
                {
                    "name": "-S --stdin",
                    "content": "Write the prompt to the standard error and read the password from the standard in‐\nput instead of using the terminal device.\n",
                    "flag": "-S",
                    "long": "--stdin"
                },
                {
                    "name": "-s --shell",
                    "content": "Run the shell specified by the SHELL environment variable if it is set or the shell\nspecified by the invoking user's password database entry.  If a command is speci‐\nfied, it is passed to the shell as a simple command using the -c option.  The com‐\nmand and any arguments are concatenated, separated by spaces, after escaping each\ncharacter (including white space) with a backslash (‘\\’) except for alphanumerics,\nunderscores, hyphens, and dollar signs.  If no command is specified, an interactive\nshell is executed.  Note that most shells behave differently when a command is\nspecified as compared to an interactive session; consult the shell's manual for de‐\ntails.\n",
                    "flag": "-s",
                    "long": "--shell"
                },
                {
                    "name": "-t --type",
                    "content": "Run the command with an SELinux security context that includes the specified type.\nIf no type is specified, the default type is derived from the role.\n",
                    "flag": "-t",
                    "long": "--type"
                },
                {
                    "name": "-U --other-user",
                    "content": "Used in conjunction with the -l option to list the privileges for user instead of\nfor the invoking user.  The security policy may restrict listing other users' priv‐\nileges.  The sudoers policy only allows root or a user with the ALL privilege on\nthe current host to use this option.\n",
                    "flag": "-U",
                    "long": "--other-user"
                },
                {
                    "name": "-T --command-timeout",
                    "content": "Used to set a timeout for the command.  If the timeout expires before the command\nhas exited, the command will be terminated.  The security policy may restrict the\nability to set command timeouts.  The sudoers policy requires that user-specified\ntimeouts be explicitly enabled.\n",
                    "flag": "-T",
                    "long": "--command-timeout"
                },
                {
                    "name": "-u --user",
                    "content": "Run the command as a user other than the default target user (usually root).  The\nuser may be either a user name or a numeric user-ID (UID) prefixed with the ‘#’\ncharacter (e.g., #0 for UID 0).  When running commands as a UID, many shells re‐\nquire that the ‘#’ be escaped with a backslash (‘\\’).  Some security policies may\nrestrict UIDs to those listed in the password database.  The sudoers policy allows\nUIDs that are not in the password database as long as the targetpw option is not\nset.  Other security policies may not support this.\n",
                    "flag": "-u",
                    "long": "--user"
                },
                {
                    "name": "-V --version",
                    "content": "Print the sudo version string as well as the version string of any configured plug‐\nins.  If the invoking user is already root, the -V option will display the argu‐\nments passed to configure when sudo was built; plugins may display additional in‐\nformation such as default options.\n",
                    "flag": "-V",
                    "long": "--version"
                },
                {
                    "name": "-v --validate",
                    "content": "Update the user's cached credentials, authenticating the user if necessary.  For\nthe sudoers plugin, this extends the sudo timeout for another 15 minutes by de‐\nfault, but does not run a command.  Not all security policies support cached cre‐\ndentials.\n\n--          The -- option indicates that sudo should stop processing command line arguments.\n\nOptions that take a value may only be specified once unless otherwise indicated in the descrip‐\ntion.  This is to help guard against problems caused by poorly written scripts that invoke sudo\nwith user-controlled input.\n\nEnvironment variables to be set for the command may also be passed on the command line in the\nform of VAR=value, e.g., LDLIBRARYPATH=/usr/local/pkg/lib.  Variables passed on the command\nline are subject to restrictions imposed by the security policy plugin.  The sudoers policy\nsubjects variables passed on the command line to the same restrictions as normal environment\nvariables with one important exception.  If the setenv option is set in sudoers, the command to\nbe run has the SETENV tag set or the command matched is ALL, the user may set variables that\nwould otherwise be forbidden.  See sudoers(5) for more information.\n",
                    "flag": "-v",
                    "long": "--validate"
                }
            ]
        },
        "COMMAND EXECUTION": {
            "content": "When sudo executes a command, the security policy specifies the execution environment for the\ncommand.  Typically, the real and effective user and group and IDs are set to match those of\nthe target user, as specified in the password database, and the group vector is initialized\nbased on the group database (unless the -P option was specified).\n\nThe following parameters may be specified by security policy:\n\n••  real and effective user-ID\n\n••  real and effective group-ID\n\n••  supplementary group-IDs\n\n••  the environment list\n\n••  current working directory\n\n••  file creation mode mask (umask)\n\n••  SELinux role and type\n\n••  scheduling priority (aka nice value)\n",
            "subsections": [
                {
                    "name": "Process model",
                    "content": "There are two distinct ways sudo can run a command.\n\nIf an I/O logging plugin is configured or if the security policy explicitly requests it, a new\npseudo-terminal (“pty”) is allocated and fork(2) is used to create a second sudo process, re‐\nferred to as the monitor.  The monitor creates a new terminal session with itself as the leader\nand the pty as its controlling terminal, calls fork(2), sets up the execution environment as\ndescribed above, and then uses the execve(2) system call to run the command in the child\nprocess.  The monitor exists to relay job control signals between the user's existing terminal\nand the pty the command is being run in.  This makes it possible to suspend and resume the com‐\nmand.  Without the monitor, the command would be in what POSIX terms an “orphaned process\ngroup” and it would not receive any job control signals from the kernel.  When the command ex‐\nits or is terminated by a signal, the monitor passes the command's exit status to the main sudo\nprocess and exits.  After receiving the command's exit status, the main sudo passes the com‐\nmand's exit status to the security policy's close function and exits.\n\nIf no pty is used, sudo calls fork(2), sets up the execution environment as described above,\nand uses the execve(2) system call to run the command in the child process.  The main sudo\nprocess waits until the command has completed, then passes the command's exit status to the se‐\ncurity policy's close function and exits.  As a special case, if the policy plugin does not de‐\nfine a close function, sudo will execute the command directly instead of calling fork(2) first.\nThe sudoers policy plugin will only define a close function when I/O logging is enabled, a pty\nis required, an SELinux role is specified, the command has an associated timeout, or the\npamsession or pamsetcred options are enabled.  Note that pamsession and pamsetcred are en‐\nabled by default on systems using PAM.\n\nOn systems that use PAM, the security policy's close function is responsible for closing the\nPAM session.  It may also log the command's exit status.\n"
                },
                {
                    "name": "Signal handling",
                    "content": "When the command is run as a child of the sudo process, sudo will relay signals it receives to\nthe command.  The SIGINT and SIGQUIT signals are only relayed when the command is being run in\na new pty or when the signal was sent by a user process, not the kernel.  This prevents the\ncommand from receiving SIGINT twice each time the user enters control-C.  Some signals, such as\nSIGSTOP and SIGKILL, cannot be caught and thus will not be relayed to the command.  As a gen‐\neral rule, SIGTSTP should be used instead of SIGSTOP when you wish to suspend a command being\nrun by sudo.\n\nAs a special case, sudo will not relay signals that were sent by the command it is running.\nThis prevents the command from accidentally killing itself.  On some systems, the reboot(8)\ncommand sends SIGTERM to all non-system processes other than itself before rebooting the sys‐\ntem.  This prevents sudo from relaying the SIGTERM signal it received back to reboot(8), which\nmight then exit before the system was actually rebooted, leaving it in a half-dead state simi‐\nlar to single user mode.  Note, however, that this check only applies to the command run by\nsudo and not any other processes that the command may create.  As a result, running a script\nthat calls reboot(8) or shutdown(8) via sudo may cause the system to end up in this undefined\nstate unless the reboot(8) or shutdown(8) are run using the exec() family of functions instead\nof system() (which interposes a shell between the command and the calling process).\n\nIf no I/O logging plugins are loaded and the policy plugin has not defined a close() function,\nset a command timeout, or required that the command be run in a new pty, sudo may execute the\ncommand directly instead of running it as a child process.\n"
                },
                {
                    "name": "Plugins",
                    "content": "Plugins may be specified via Plugin directives in the sudo.conf(5) file.  They may be loaded as\ndynamic shared objects (on systems that support them), or compiled directly into the sudo bi‐\nnary.  If no sudo.conf(5) file is present, or if it doesn't contain any Plugin lines, sudo will\nuse sudoers(5) for the policy, auditing, and I/O logging plugins.  See the sudo.conf(5) manual\nfor details of the /etc/sudo.conf file and the sudoplugin(5) manual for more information about\nthe sudo plugin architecture.\n"
                }
            ]
        },
        "EXIT VALUE": {
            "content": "Upon successful execution of a command, the exit status from sudo will be the exit status of\nthe program that was executed.  If the command terminated due to receipt of a signal, sudo will\nsend itself the same signal that terminated the command.\n\nIf the -l option was specified without a command, sudo will exit with a value of 0 if the user\nis allowed to run sudo and they authenticated successfully (as required by the security pol‐\nicy).  If a command is specified with the -l option, the exit value will only be 0 if the com‐\nmand is permitted by the security policy, otherwise it will be 1.\n\nIf there is an authentication failure, a configuration/permission problem, or if the given com‐\nmand cannot be executed, sudo exits with a value of 1.  In the latter case, the error string is\nprinted to the standard error.  If sudo cannot stat(2) one or more entries in the user's PATH,\nan error is printed to the standard error.  (If the directory does not exist or if it is not\nreally a directory, the entry is ignored and no error is printed.)  This should not happen un‐\nder normal circumstances.  The most common reason for stat(2) to return “permission denied” is\nif you are running an automounter and one of the directories in your PATH is on a machine that\nis currently unreachable.\n",
            "subsections": []
        },
        "SECURITY NOTES": {
            "content": "sudo tries to be safe when executing external commands.\n\nTo prevent command spoofing, sudo checks \".\" and \"\" (both denoting current directory) last when\nsearching for a command in the user's PATH (if one or both are in the PATH).  Depending on the\nsecurity policy, the user's PATH environment variable may be modified, replaced, or passed un‐\nchanged to the program that sudo executes.\n\nUsers should never be granted sudo privileges to execute files that are writable by the user or\nthat reside in a directory that is writable by the user.  If the user can modify or replace the\ncommand there is no way to limit what additional commands they can run.\n\nPlease note that sudo will normally only log the command it explicitly runs.  If a user runs a\ncommand such as sudo su or sudo sh, subsequent commands run from that shell are not subject to\nsudo's security policy.  The same is true for commands that offer shell escapes (including most\neditors).  If I/O logging is enabled, subsequent commands will have their input and/or output\nlogged, but there will not be traditional logs for those commands.  Because of this, care must\nbe taken when giving users access to commands via sudo to verify that the command does not in‐\nadvertently give the user an effective root shell.  For information on ways to address this,\nplease see the Preventing shell escapes section in sudoers(5).\n\nTo prevent the disclosure of potentially sensitive information, sudo disables core dumps by de‐\nfault while it is executing (they are re-enabled for the command that is run).  This historical\npractice dates from a time when most operating systems allowed set-user-ID processes to dump\ncore by default.  To aid in debugging sudo crashes, you may wish to re-enable core dumps by\nsetting “disablecoredump” to false in the sudo.conf(5) file as follows:\n\nSet disablecoredump false\n\nSee the sudo.conf(5) manual for more information.\n",
            "subsections": []
        },
        "ENVIRONMENT": {
            "content": "sudo utilizes the following environment variables.  The security policy has control over the\nactual content of the command's environment.\n\nEDITOR           Default editor to use in -e (sudoedit) mode if neither SUDOEDITOR nor VISUAL\nis set.\n\nMAIL             Set to the mail spool of the target user when the -i option is specified, or\nwhen envreset is enabled in sudoers (unless MAIL is present in the envkeep\nlist).\n\nHOME             Set to the home directory of the target user when the -i or -H options are\nspecified, when the -s option is specified and sethome is set in sudoers,\nwhen alwayssethome is enabled in sudoers, or when envreset is enabled in\nsudoers and HOME is not present in the envkeep list.\n\nLOGNAME          Set to the login name of the target user when the -i option is specified, when\nthe setlogname option is enabled in sudoers, or when the envreset option is\nenabled in sudoers (unless LOGNAME is present in the envkeep list).\n\nPATH             May be overridden by the security policy.\n\nSHELL            Used to determine shell to run with -s option.\n\nSUDOASKPASS     Specifies the path to a helper program used to read the password if no termi‐\nnal is available or if the -A option is specified.\n\nSUDOCOMMAND     Set to the command run by sudo, including command line arguments.  The command\nline arguments are truncated at 4096 characters to prevent a potential execu‐\ntion error.\n\nSUDOEDITOR      Default editor to use in -e (sudoedit) mode.\n\nSUDOGID         Set to the group-ID of the user who invoked sudo.\n\nSUDOPROMPT      Used as the default password prompt unless the -p option was specified.\n\nSUDOPS1         If set, PS1 will be set to its value for the program being run.\n\nSUDOUID         Set to the user-ID of the user who invoked sudo.\n\nSUDOUSER        Set to the login name of the user who invoked sudo.\n\nUSER             Set to the same value as LOGNAME, described above.\n\nVISUAL           Default editor to use in -e (sudoedit) mode if SUDOEDITOR is not set.\n",
            "subsections": []
        },
        "FILES": {
            "content": "/etc/sudo.conf            sudo front-end configuration\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Note: the following examples assume a properly configured security policy.\n\nTo get a file listing of an unreadable directory:\n\n$ sudo ls /usr/local/protected\n\nTo list the home directory of user yaz on a machine where the file system holding ~yaz is not\nexported as root:\n\n$ sudo -u yaz ls ~yaz\n\nTo edit the index.html file as user www:\n\n$ sudoedit -u www ~www/htdocs/index.html\n\nTo view system logs only accessible to root and users in the adm group:\n\n$ sudo -g adm more /var/log/syslog\n\nTo run an editor as jim with a different primary group:\n\n$ sudoedit -u jim -g audio ~jim/sound.txt\n\nTo shut down a machine:\n\n$ sudo shutdown -r +15 \"quick reboot\"\n\nTo make a usage listing of the directories in the /home partition.  Note that this runs the\ncommands in a sub-shell to make the cd and file redirection work.\n\n$ sudo sh -c \"cd /home ; du -s * | sort -rn > USAGE\"\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "Error messages produced by sudo include:\n\nediting files in a writable directory is not permitted\nBy default, sudoedit does not permit editing a file when any of the parent directories\nare writable by the invoking user.  This avoids a race condition that could allow the\nuser to overwrite an arbitrary file.  See the sudoeditcheckdir option in sudoers(5) for\nmore information.\n\nediting symbolic links is not permitted\nBy default, sudoedit does not follow symbolic links when opening files.  See the\nsudoeditfollow option in sudoers(5) for more information.\n\neffective uid is not 0, is sudo installed setuid root?\nsudo was not run with root privileges.  The sudo binary must be owned by the root user\nand have the set-user-ID bit set.  Also, it must not be located on a file system mounted\nwith the ‘nosuid’ option or on an NFS file system that maps uid 0 to an unprivileged uid.\n\neffective uid is not 0, is sudo on a file system with the 'nosuid' option set or an NFS file\nsystem without root privileges?\nsudo was not run with root privileges.  The sudo binary has the proper owner and permis‐\nsions but it still did not run with root privileges.  The most common reason for this is\nthat the file system the sudo binary is located on is mounted with the ‘nosuid’ option or\nit is an NFS file system that maps uid 0 to an unprivileged uid.\n\nfatal error, unable to load plugins\nAn error occurred while loading or initializing the plugins specified in sudo.conf(5).\n\ninvalid environment variable name\nOne or more environment variable names specified via the -E option contained an equal\nsign (‘=’).  The arguments to the -E option should be environment variable names without\nan associated value.\n\nno password was provided\nWhen sudo tried to read the password, it did not receive any characters.  This may happen\nif no terminal is available (or the -S option is specified) and the standard input has\nbeen redirected from /dev/null.\n\na terminal is required to read the password\nsudo needs to read the password but there is no mechanism available for it to do so.  A\nterminal is not present to read the password from, sudo has not been configured to read\nfrom the standard input, the -S option was not used, and no askpass helper has been spec‐\nified either via the sudo.conf(5) file or the SUDOASKPASS environment variable.\n\nno writable temporary directory found\nsudoedit was unable to find a usable temporary directory in which to store its intermedi‐\nate files.\n\nThe “no new privileges” flag is set, which prevents sudo from running as root.\nsudo was run by a process that has the Linux “no new privileges” flag is set.  This\ncauses the set-user-ID bit to be ignored when running an executable, which will prevent\nsudo from functioning.  The most likely cause for this is running sudo within a container\nthat sets this flag.  Check the documentation to see if it is possible to configure the\ncontainer such that the flag is not set.\n\nsudo must be owned by uid 0 and have the setuid bit set\nsudo was not run with root privileges.  The sudo binary does not have the correct owner\nor permissions.  It must be owned by the root user and have the set-user-ID bit set.\n\nsudoedit is not supported on this platform\nIt is only possible to run sudoedit on systems that support setting the effective user-\nID.\n\ntimed out reading password\nThe user did not enter a password before the password timeout (5 minutes by default) ex‐\npired.\n\nyou do not exist in the passwd database\nYour user-ID does not appear in the system passwd database.\n\nyou may not specify environment variables in edit mode\nIt is only possible to specify environment variables when running a command.  When edit‐\ning a file, the editor is run with the user's environment unmodified.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "su(1), stat(2), logincap(3), passwd(5), sudo.conf(5), sudoplugin(5), sudoers(5),\nsudoerstimestamp(5), sudoreplay(8), visudo(8)\n",
            "subsections": []
        },
        "HISTORY": {
            "content": "See the HISTORY file in the sudo distribution (https://www.sudo.ws/history.html) for a brief\nhistory of sudo.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Many people have worked on sudo over the years; this version consists of code written primarily\nby:\n\nTodd C. Miller\n\nSee the CONTRIBUTORS file in the sudo distribution (https://www.sudo.ws/contributors.html) for\nan exhaustive list of people who have contributed to sudo.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "There is no easy way to prevent a user from gaining a root shell if that user is allowed to run\narbitrary commands via sudo.  Also, many programs (such as editors) allow the user to run com‐\nmands via shell escapes, thus avoiding sudo's checks.  However, on most systems it is possible\nto prevent shell escapes with the sudoers(5) plugin's noexec functionality.\n\nIt is not meaningful to run the cd command directly via sudo, e.g.,\n\n$ sudo cd /usr/local/protected\n\nsince when the command exits the parent process (your shell) will still be the same.  Please\nsee the EXAMPLES section for more information.\n\nRunning shell scripts via sudo can expose the same kernel bugs that make set-user-ID shell\nscripts unsafe on some operating systems (if your OS has a /dev/fd/ directory, set-user-ID\nshell scripts are generally safe).\n",
            "subsections": []
        },
        "BUGS": {
            "content": "If you feel you have found a bug in sudo, please submit a bug report at\nhttps://bugzilla.sudo.ws/\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Limited free support is available via the sudo-users mailing list, see\nhttps://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or search the archives.\n",
            "subsections": []
        },
        "DISCLAIMER": {
            "content": "sudo is provided “AS IS” and any express or implied warranties, including, but not limited to,\nthe implied warranties of merchantability and fitness for a particular purpose are disclaimed.\nSee the LICENSE file distributed with sudo or https://www.sudo.ws/license.html for complete de‐\ntails.\n",
            "subsections": []
        },
        "Sudo 1.9.9                     January 19, 2022                     Sudo 1.9.9": {
            "content": "",
            "subsections": []
        }
    },
    "summary": "sudo, sudoedit — execute a command as another user",
    "flags": [
        {
            "flag": "-A",
            "long": "--askpass",
            "arg": null,
            "description": "Normally, if sudo requires a password, it will read it from the user's terminal. If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard out‐ put. If the SUDOASKPASS environment variable is set, it specifies the path to the helper program. Otherwise, if sudo.conf(5) contains a line specifying the askpass program, that value will be used. For example: # Path to askpass helper program Path askpass /usr/X11R6/bin/ssh-askpass If no askpass program is available, sudo will exit with an error."
        },
        {
            "flag": "-B",
            "long": "--bell",
            "arg": null,
            "description": "tion has no effect if an askpass program is used."
        },
        {
            "flag": "-b",
            "long": "--background",
            "arg": null,
            "description": "Run the given command in the background. Note that it is not possible to use shell job control to manipulate background processes started by sudo. Most interactive commands will fail to work properly in background mode."
        },
        {
            "flag": "-C",
            "long": "--close-from",
            "arg": null,
            "description": "Close all file descriptors greater than or equal to num before executing a command. Values less than three are not permitted. By default, sudo will close all open file descriptors other than standard input, standard output, and standard error when executing a command. The security policy may restrict the user's ability to use this option. The sudoers policy only permits use of the -C option when the ad‐ ministrator has enabled the closefromoverride option."
        },
        {
            "flag": "-D",
            "long": "--chdir",
            "arg": null,
            "description": "Run the command in the specified directory instead of the current working direc‐ tory. The security policy may return an error if the user does not have permission to specify the working directory."
        },
        {
            "flag": "-E",
            "long": "--preserve-env",
            "arg": null,
            "description": "Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment."
        },
        {
            "flag": "",
            "long": "--preserve-env",
            "arg": "list",
            "description": "Indicates to the security policy that the user wishes to add the comma-separated list of environment variables to those preserved from the user's environment. The security policy may return an error if the user does not have permission to pre‐ serve the environment. This option may be specified multiple times."
        },
        {
            "flag": "-e",
            "long": "--edit",
            "arg": null,
            "description": "string \"sudoedit\" is used when consulting the security policy. If the user is au‐ thorized by the policy, the following steps are taken: 1. Temporary copies are made of the files to be edited with the owner set to the invoking user. 2. The editor specified by the policy is run to edit the temporary files. The sudoers policy uses the SUDOEDITOR, VISUAL and EDITOR environment variables (in that order). If none of SUDOEDITOR, VISUAL or EDITOR are set, the first program listed in the editor sudoers(5) option is used. 3. If they have been modified, the temporary files are copied back to their orig‐ inal location and the temporary versions are removed. To help prevent the editing of unauthorized files, the following restrictions are enforced unless explicitly allowed by the security policy: •• Symbolic links may not be edited (version 1.8.15 and higher). •• Symbolic links along the path to be edited are not followed when the parent di‐ rectory is writable by the invoking user unless that user is root (version 1.8.16 and higher). •• Files located in a directory that is writable by the invoking user may not be edited unless that user is root (version 1.8.16 and higher). Users are never allowed to edit device special files. If the specified file does not exist, it will be created. Note that unlike most commands run by sudo, the editor is run with the invoking user's environment unmod‐ ified. If the temporary file becomes empty after editing, the user will be prompted before it is installed. If, for some reason, sudo is unable to update a file with its edited version, the user will receive a warning and the edited copy will remain in a temporary file."
        },
        {
            "flag": "-g",
            "long": "--group",
            "arg": null,
            "description": "Run the command with the primary group set to group instead of the primary group specified by the target user's password database entry. The group may be either a group name or a numeric group-ID (GID) prefixed with the ‘#’ character (e.g., #0 for GID 0). When running a command as a GID, many shells require that the ‘#’ be escaped with a backslash (‘\\’). If no -u option is specified, the command will be run as the invoking user. In either case, the primary group will be set to group. The sudoers policy permits any of the target user's groups to be specified via the -g option as long as the -P option is not in use."
        },
        {
            "flag": "-H",
            "long": "--set-home",
            "arg": null,
            "description": "Request that the security policy set the HOME environment variable to the home di‐ rectory specified by the target user's password database entry. Depending on the policy, this may be the default behavior."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": ""
        },
        {
            "flag": "-h",
            "long": "--host",
            "arg": null,
            "description": "Run the command on the specified host if the security policy plugin supports remote commands. Note that the sudoers plugin does not currently support running remote commands. This may also be used in conjunction with the -l option to list a user's privileges for the remote host."
        },
        {
            "flag": "-i",
            "long": "--login",
            "arg": null,
            "description": "Run the shell specified by the target user's password database entry as a login shell. This means that login-specific resource files such as .profile, .bashprofile, or .login will be read by the shell. If a command is specified, it is passed to the shell as a simple command using the -c option. The command and any arguments are concatenated, separated by spaces, after escaping each character (including white space) with a backslash (‘\\’) except for alphanumerics, under‐ scores, hyphens, and dollar signs. If no command is specified, an interactive shell is executed. sudo attempts to change to that user's home directory before running the shell. The command is run with an environment similar to the one a user would receive at log in. Note that most shells behave differently when a com‐ mand is specified as compared to an interactive session; consult the shell's manual for details. The Command environment section in the sudoers(5) manual documents how the -i option affects the environment in which a command is run when the sudoers policy is in use."
        },
        {
            "flag": "-K",
            "long": "--remove-timestamp",
            "arg": null,
            "description": "Similar to the -k option, except that it removes the user's cached credentials en‐ tirely and may not be used in conjunction with a command or other option. This op‐ tion does not require a password. Not all security policies support credential caching."
        },
        {
            "flag": "-k",
            "long": "--reset-timestamp",
            "arg": null,
            "description": "When used without a command, invalidates the user's cached credentials. In other words, the next time sudo is run a password will be required. This option does not require a password, and was added to allow a user to revoke sudo permissions from a .logout file. When used in conjunction with a command or an option that may require a password, this option will cause sudo to ignore the user's cached credentials. As a result, sudo will prompt for a password (if one is required by the security policy) and will not update the user's cached credentials. Not all security policies support credential caching."
        },
        {
            "flag": "-l",
            "long": "--list",
            "arg": null,
            "description": "voking user (or the user specified by the -U option) on the current host. A longer list format is used if this option is specified multiple times and the security policy supports a verbose output format. If a command is specified and is permitted by the security policy, the fully-quali‐ fied path to the command is displayed along with any command line arguments. If a command is specified but not allowed by the policy, sudo will exit with a status value of 1."
        },
        {
            "flag": "-n",
            "long": "--non-interactive",
            "arg": null,
            "description": "Avoid prompting the user for input of any kind. If a password is required for the command to run, sudo will display an error message and exit."
        },
        {
            "flag": "-P",
            "long": "--preserve-groups",
            "arg": null,
            "description": "Preserve the invoking user's group vector unaltered. By default, the sudoers pol‐ icy will initialize the group vector to the list of groups the target user is a member of. The real and effective group-IDs, however, are still set to match the target user."
        },
        {
            "flag": "-p",
            "long": "--prompt",
            "arg": null,
            "description": "Use a custom password prompt with optional escape sequences. The following percent (‘%’) escape sequences are supported by the sudoers policy: %H expanded to the host name including the domain name (only if the machine's host name is fully qualified or the fqdn option is set in sudoers(5)) %h expanded to the local host name without the domain name %p expanded to the name of the user whose password is being requested (respects the rootpw, targetpw, and runaspw flags in sudoers(5)) %U expanded to the login name of the user the command will be run as (defaults to root unless the -u option is also specified) %u expanded to the invoking user's login name %% two consecutive ‘%’ characters are collapsed into a single ‘%’ character The custom prompt will override the default prompt specified by either the security policy or the SUDOPROMPT environment variable. On systems that use PAM, the cus‐ tom prompt will also override the prompt specified by a PAM module unless the passpromptoverride flag is disabled in sudoers."
        },
        {
            "flag": "-R",
            "long": "--chroot",
            "arg": null,
            "description": "Change to the specified root directory (see chroot(8)) before running the command. The security policy may return an error if the user does not have permission to specify the root directory."
        },
        {
            "flag": "-r",
            "long": "--role",
            "arg": null,
            "description": "Run the command with an SELinux security context that includes the specified role."
        },
        {
            "flag": "-S",
            "long": "--stdin",
            "arg": null,
            "description": "Write the prompt to the standard error and read the password from the standard in‐ put instead of using the terminal device."
        },
        {
            "flag": "-s",
            "long": "--shell",
            "arg": null,
            "description": "Run the shell specified by the SHELL environment variable if it is set or the shell specified by the invoking user's password database entry. If a command is speci‐ fied, it is passed to the shell as a simple command using the -c option. The com‐ mand and any arguments are concatenated, separated by spaces, after escaping each character (including white space) with a backslash (‘\\’) except for alphanumerics, underscores, hyphens, and dollar signs. If no command is specified, an interactive shell is executed. Note that most shells behave differently when a command is specified as compared to an interactive session; consult the shell's manual for de‐ tails."
        },
        {
            "flag": "-t",
            "long": "--type",
            "arg": null,
            "description": "Run the command with an SELinux security context that includes the specified type. If no type is specified, the default type is derived from the role."
        },
        {
            "flag": "-U",
            "long": "--other-user",
            "arg": null,
            "description": "Used in conjunction with the -l option to list the privileges for user instead of for the invoking user. The security policy may restrict listing other users' priv‐ ileges. The sudoers policy only allows root or a user with the ALL privilege on the current host to use this option."
        },
        {
            "flag": "-T",
            "long": "--command-timeout",
            "arg": null,
            "description": "Used to set a timeout for the command. If the timeout expires before the command has exited, the command will be terminated. The security policy may restrict the ability to set command timeouts. The sudoers policy requires that user-specified timeouts be explicitly enabled."
        },
        {
            "flag": "-u",
            "long": "--user",
            "arg": null,
            "description": "Run the command as a user other than the default target user (usually root). The user may be either a user name or a numeric user-ID (UID) prefixed with the ‘#’ character (e.g., #0 for UID 0). When running commands as a UID, many shells re‐ quire that the ‘#’ be escaped with a backslash (‘\\’). Some security policies may restrict UIDs to those listed in the password database. The sudoers policy allows UIDs that are not in the password database as long as the targetpw option is not set. Other security policies may not support this."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "Print the sudo version string as well as the version string of any configured plug‐ ins. If the invoking user is already root, the -V option will display the argu‐ ments passed to configure when sudo was built; plugins may display additional in‐ formation such as default options."
        },
        {
            "flag": "-v",
            "long": "--validate",
            "arg": null,
            "description": "Update the user's cached credentials, authenticating the user if necessary. For the sudoers plugin, this extends the sudo timeout for another 15 minutes by de‐ fault, but does not run a command. Not all security policies support cached cre‐ dentials. -- The -- option indicates that sudo should stop processing command line arguments. Options that take a value may only be specified once unless otherwise indicated in the descrip‐ tion. This is to help guard against problems caused by poorly written scripts that invoke sudo with user-controlled input. Environment variables to be set for the command may also be passed on the command line in the form of VAR=value, e.g., LDLIBRARYPATH=/usr/local/pkg/lib. Variables passed on the command line are subject to restrictions imposed by the security policy plugin. The sudoers policy subjects variables passed on the command line to the same restrictions as normal environment variables with one important exception. If the setenv option is set in sudoers, the command to be run has the SETENV tag set or the command matched is ALL, the user may set variables that would otherwise be forbidden. See sudoers(5) for more information."
        }
    ],
    "examples": [
        "Note: the following examples assume a properly configured security policy.",
        "To get a file listing of an unreadable directory:",
        "$ sudo ls /usr/local/protected",
        "To list the home directory of user yaz on a machine where the file system holding ~yaz is not",
        "exported as root:",
        "$ sudo -u yaz ls ~yaz",
        "To edit the index.html file as user www:",
        "$ sudoedit -u www ~www/htdocs/index.html",
        "To view system logs only accessible to root and users in the adm group:",
        "$ sudo -g adm more /var/log/syslog",
        "To run an editor as jim with a different primary group:",
        "$ sudoedit -u jim -g audio ~jim/sound.txt",
        "To shut down a machine:",
        "$ sudo shutdown -r +15 \"quick reboot\"",
        "To make a usage listing of the directories in the /home partition.  Note that this runs the",
        "commands in a sub-shell to make the cd and file redirection work.",
        "$ sudo sh -c \"cd /home ; du -s * | sort -rn > USAGE\""
    ],
    "see_also": [
        {
            "name": "su",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/su/1/json"
        },
        {
            "name": "stat",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/stat/2/json"
        },
        {
            "name": "logincap",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/logincap/3/json"
        },
        {
            "name": "passwd",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/passwd/5/json"
        },
        {
            "name": "sudo.conf",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/sudo.conf/5/json"
        },
        {
            "name": "sudoplugin",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/sudoplugin/5/json"
        },
        {
            "name": "sudoers",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/sudoers/5/json"
        },
        {
            "name": "sudoerstimestamp",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/sudoerstimestamp/5/json"
        },
        {
            "name": "sudoreplay",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/sudoreplay/8/json"
        },
        {
            "name": "visudo",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/visudo/8/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Execute a single command as the superuser or another user.",
        "examples": [
            {
                "description": "Run a command as the superuser",
                "command": "sudo {{less /var/log/syslog}}"
            },
            {
                "description": "Edit a file as the superuser with your default editor",
                "command": "sudo {{-e|--edit}} {{/etc/fstab}}"
            },
            {
                "description": "Run a command as another user and/or group",
                "command": "sudo {{-u|--user}} {{user}} {{-g|--group}} {{group}} {{id -a}}"
            },
            {
                "description": "Repeat the last command prefixed with `sudo` (only in Bash, Zsh, etc.)",
                "command": "sudo !!"
            },
            {
                "description": "Launch the default shell with superuser privileges and run login-specific files (`.profile`, `.bash_profile`, etc.)",
                "command": "sudo {{-i|--login}}"
            },
            {
                "description": "Launch the default shell with superuser privileges without changing the environment",
                "command": "sudo {{-s|--shell}}"
            },
            {
                "description": "Launch the default shell as the specified user, loading the user's environment and reading login-specific files (`.profile`, `.bash_profile`, etc.)",
                "command": "sudo {{-i|--login}} {{-u|--user}} {{user}}"
            },
            {
                "description": "List the allowed (and forbidden) commands for the invoking user in longer format",
                "command": "sudo {{-ll|--list --list}}"
            }
        ]
    }
}