SUDO(8)
โจ SUDO(8) ยท System Manager's Manual โจ
๐ NAME
okay so the name section is short and sweet ๐ธ: sudo, sudoedit โ execute a command as another user ๐
๐งพ SYNOPSIS
sudo -h | -K | -k | -V
sudo -v [-ABkNnS] [-g group] [-h host] [-p prompt] [-u user]
sudo -l [-ABkNnS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
[command [arg ...]]
sudo [-ABbEHnPS] [-C num] [-D directory] [-g group] [-h host]
[-p prompt] [-R directory] [-r role] [-t type] [-T timeout]
[-u user] [VAR=value] [-i | -s] [command [arg ...]]
sudoedit [-ABkNnS] [-C num] [-D directory] [-g group] [-h host]
[-p prompt] [-R directory] [-r role] [-t type] [-T timeout]
[-u user] file ...
๐ DESCRIPTION
okay so sudo lets a user who's allowed to do it run a command as the superuser or some other user ๐, as long as the security policy says yes. The user name that gets checked against the policy comes from the invoking user's real user-ID, not their effective one ๐ฆ.
sudo has a plugin architecture for security policies, auditing, and input/output logging โจ. Third parties can build and share their own plugins that play nicely with the sudo front-end ๐ง. The default security policy is sudoers, which is configured through the file /etc/sudoers, or through LDAP ๐. See the โPluginsโ section for more info ๐.
The security policy decides what privileges, if any, a user gets when running sudo ๐ฅ. It might make the user prove who they are with a password or some other authentication method. If authentication is required and the password isn't entered within a configurable time limit, sudo exits ๐. That limit is policy-specific, and the default password prompt timeout for the sudoers security policy is 0 minutes, so no pressure ๐.
Security policies may support credential caching, which lets the user run sudo again for a while without re-authenticating โฐ. By default, the sudoers policy caches credentials per terminal for 15 minutes ๐. See the timestamp_type and timestamp_timeout options in sudoers(5) for more details. Running sudo with the -v option refreshes the cached credentials without running a command ๐ซถ.
โ ๏ธ On systems where sudo is the main way to get superuser privileges, it is imperative to avoid syntax errors in the security policy configuration files ๐ญ. For the default security policy, sudoers(5), make your changes with the visudo(8) utility, which makes sure no syntax errors sneak in ๐ก๏ธ.
When invoked as sudoedit, the -e option (described below) is implied ๐.
Security policies and audit plugins may log successful and failed attempts to run sudo ๐. If an I/O plugin is configured, the running command's input and output may get logged too ๐ฌ.
๐ OPTIONS
The options are as follows, bestie ๐ :
-A,--askpassโ normally, if sudo needs a password, it reads it straight from the user's terminal. With-A(askpass), a helper program (possibly graphical ๐ช) is run instead, which reads the password and prints it to the standard output. If theSUDO_ASKPASSenvironment variable is set, it holds the path to that helper program. Otherwise, if sudo.conf(5) has a line naming the askpass program, that value gets used. For example:
# Path to askpass helper program
Path askpass /usr/bin/ssh-askpass
If there's no askpass program available, sudo exits with an error ๐ค.
-B,--bellโ rings the bell as part of the password prompt when a terminal is present ๐. This does nothing if an askpass program is being used ๐.-b,--backgroundโ runs the given command in the background ๐. You can't use shell job control to manage background processes started by sudo, so most interactive commands will fail to work properly in background mode ๐.-C num,--close-from=numโ closes all file descriptors greater than or equal tonumbefore running a command ๐ช. Values less than3aren't allowed ๐ซ. By default, sudo closes every open file descriptor except standard input, standard output, and standard error when it runs a command. The security policy might restrict your ability to use this option. The sudoers policy only lets you use-Cif the administrator has turned on theclosefrom_overrideoption ๐.-D directory,--chdir=directoryโ runs the command in the specified directory instead of the current working directory ๐. The security policy may throw an error if you don't have permission to pick the working directory ๐ .-E,--preserve-envโ tells the security policy that you want to keep your existing environment variables โจ. The policy may return an error if you don't have permission to preserve the environment ๐ฅฒ.--preserve-env=listโ tells the security policy you want to add the comma-separated list of environment variables to the ones preserved from your environment ๐. Same deal as above: the policy may error if you aren't allowed to preserve the environment. This option can be specified multiple times ๐.-e,--editโ edits one or more files instead of running a command ๐. Instead of a path name, the string "sudoedit" is used when consulting the security policy ๐ต๏ธ. If the policy authorizes you, these steps happen:- Temporary copies are made of the files to be edited, with the owner set to the invoking user ๐งโ๐จ.
- The editor specified by the policy runs to edit the temporary files. The sudoers policy checks the
SUDO_EDITOR,VISUALandEDITORenvironment variables (in that order) ๐๏ธ. If none ofSUDO_EDITOR,VISUALorEDITORare set, the first program listed in theeditorsudoers(5) option is used. - If they've been modified, the temporary files get copied back to their original location and the temporary versions are removed ๐งน.
To help stop people from editing files they shouldn't, these restrictions are enforced unless the security policy explicitly allows otherwise ๐ก๏ธ:
- 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 directory 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 doesn't exist, it gets created โจ. Unlike most commands run by sudo, the editor runs with the invoking user's environment unmodified ๐ท. If the temporary file is empty after editing, the user gets prompted before it's installed ๐ซฃ. If, for some reason, sudo can't update a file with its edited version, the user gets a warning and the edited copy stays in a temporary file ๐ฌ.
-g group,--group=groupโ runs the command with the primary group set togroupinstead of the primary group from the target user's password database entry ๐. The group can be a group name or a numeric group-ID (GID) prefixed with the#character (e.g.,#0for GID 0). When running a command as a GID, many shells require that the#be escaped with a backslash (\) ๐. If no-uoption is given, the command runs as the invoking user. Either way, the primary group gets set togroup๐. The sudoers policy lets you specify any of the target user's groups with-gas long as the-Poption isn't in use ๐ฏ.-H,--set-homeโ asks the security policy to set theHOMEenvironment variable to the home directory from the target user's password database entry ๐ . Depending on the policy, this might be the default behavior already ๐คทโโ๏ธ.-h,--helpโ displays a short help message to the standard output and exits ๐.-h host,--host=hostโ runs the command on the specified host, if the security policy plugin supports remote commands ๐. The sudoers plugin doesn't currently support running remote commands ๐ . This can also be used with the-loption to list a user's privileges for the remote host ๐.-i,--loginโ runs the shell from the target user's password database entry as a login shell ๐. That means login-specific resource files like.profile,.bash_profile, or.loginwill be read by the shell ๐. If a command is given, it's passed to the shell as a simple command using the-coption. The command and any args get concatenated, separated by spaces, after each character (including white space) is escaped with a backslash (\), except for alphanumerics, underscores, hyphens, and dollar signs ๐งต. If no command is given, an interactive shell runs ๐. sudo tries to change to that user's home directory before running the shell ๐ก. The command runs with an environment similar to the one a user would get at login ๐ธ. Most shells behave differently when a command is specified versus an interactive session, so check your shell's manual for details ๐. The Command environment section in the sudoers(5) manual documents how-iaffects the environment a command runs in when the sudoers policy is in use ๐ .-K,--remove-timestampโ similar to-k, except it removes every cached credential for the user, no matter the terminal or parent process ID ๐งน. The next time sudo runs, a password must be entered if the security policy requires authentication ๐. You can't use-Ktogether with a command or any other option ๐ โโ๏ธ. This option doesn't need a password ๐ซถ. Not all security policies support credential caching, so this might not do anything for you ๐คทโโ๏ธ.-k,--reset-timestampโ okay so, without a command this one wipes your cached credentials for the current session ๐งน Next time you run sudo in that session, you'll need to type your password if the security policy wants authentication. By default the sudoers policy keeps a separate cache record for each terminal (or the parent process ID if there's no terminal), so-kcan't mess with sudo commands running in a different terminal session ๐ See thetimestamp_typeoption in sudoers(5) for more. This one doesn't need a password, and it was added so you can revoke sudo permissions from a.logoutfile ๐ช
When you pair -k with a command or an option that might need a password, sudo ignores your cached credentials. So it'll prompt you for a password (if the security policy requires one) and won't update your cached credentials either. Main character move ๐
Not all security policies support credential caching.
-l,--listโ list your privileges ๐ Without a command, this shows what the invoking user (or the user picked with-U) can do on the current host. If you specify it multiple times and the security policy supports verbose output, you get a longer list ๐
If you give a command that the policy allows for the invoking user (or the user picked with -U) on this host, sudo shows the fully-qualified path to the command along with any args. Use -l more than once (if the policy supports it) and the matching rule shows up in verbose format next to the command ๐ If the command isn't allowed by the policy, sudo exits with a status value of 1. Big oof ๐
-N,--no-updateโ don't update the cached credentials, even if you authenticate successfully โ Unlike-k, existing cached credentials still get used if they're valid. To check whether your cached credentials are valid (or whether no authentication is needed at all), you can use:
sudo -Nnv
Not all security policies support credential caching.
-n,--non-interactiveโ no prompting, bestie ๐ค sudo won't ask you for any input of any kind. If the command needs a password, sudo displays an error message and exits instead.-P,--preserve-groupsโ keeps your group vector exactly as it is ๐ซถ By default the sudoers policy resets the group vector to the list of groups the target user belongs to. The real and effective group-IDs still get set to match the target user, though.-p prompt,--prompt=promptโ swap in a custom password prompt โจ You can use these percent (%) escape sequences, which the sudoers policy supports:%Hโ the full host name, domain included (only if the machine's host name is fully qualified or thefqdnoption is set in sudoers(5)) ๐%hโ the local host name, no domain ๐%pโ the name of the user whose password is being requested (respects therootpw,targetpw, andrunaspwflags in sudoers(5)) ๐%Uโ the login name of the user the command will run as (defaults to root unless-uis also specified) ๐%uโ your invoking user's login name ๐ง%%โ two%characters in a row collapse into a single%๐
Your custom prompt overrides the default prompt from either the security policy or the SUDO_PROMPT environment variable. On systems that use PAM, it also overrides the prompt set by a PAM module, unless the passprompt_override flag is disabled in sudoers. ๐
-R directory,--chroot=directoryโ change to the specified root directory (see chroot(8)) before running the command ๐ณ The security policy might throw an error if you don't have permission to pick that root directory.
This option is deprecated and will be removed in a future version of sudo. Don't get too attached to it, bestie ๐ญ
-r role,--role=roleโ run the command with an SELinux security context that includes the role you specify ๐ฆ-S,--stdinโ the prompt goes to standard error, and the password gets read from standard input instead of the terminal device โจ๏ธ Handy for scripts ๐ง-s,--shellโ run a shell ๐ It uses the shell in theSHELLenvironment variable if that's set, or the shell from the invoking user's password database entry. If you give a command, it gets passed to the shell as a simple command using the-coption. The command and its args get joined with spaces, after every character (including white space) is escaped with a backslash (\), except for alphanumerics, underscores, hyphens, and dollar signs. If there's no command, you get an interactive shell โจ Most shells act differently when a command is given versus an interactive session, so check your shell's manual for the deets ๐-t type,--type=typeโ run the command with an SELinux security context that includes the type you specify ๐ If you don't specify a type, the default type comes from the role.-U user,--other-user=userโ pairs with-lto list the privileges for user instead of for you ๐ The security policy might not let you peek at other users' privileges. With the sudoers policy,-Uis limited to root and to users who have the "list" privilege for the specified user, or who can run any command as root or user on the current host ๐-T timeout,--command-timeout=timeoutโ set a timeout for the command โฐ If the timeout runs out before the command exits, the command gets terminated ๐ The security policy might restrict your ability to set timeouts. The sudoers policy requires that user-specified timeouts be explicitly enabled.-u user,--user=userโ run the command as someone other than the default target user (usually root) ๐ง The user can be a user name or a numeric user-ID (UID) prefixed with the#character (e.g.,#0for UID 0). When running commands as a UID, many shells need the#escaped with a backslash (\) ๐ Some security policies only allow UIDs that are in the password database. The sudoers policy allows UIDs that aren't in the password database, as long as thetargetpwoption isn't set. Other security policies might not support this at all.-V,--versionโ prints the sudo version string, plus the version string of any configured plugins ๐ข If the invoking user is already root,-Valso displays the options passed to configure when sudo was built. Plugins might show extra info, like default options ๐ค-v,--validateโ update your cached credentials, authenticating you if needed โ For the sudoers plugin, this extends the sudo timeout by another 15 minutes by default, but it doesn't run a command. Not all security policies support cached credentials.--โ the--marks the end of the sudo options ๐ง Anything after it gets passed to the command.
Options that take a value can only be specified once, unless the description says otherwise ๐ โโ๏ธ This helps protect against problems caused by poorly written scripts that invoke sudo with user-controlled input. Protect yourself, babe ๐ก๏ธ
You can also pass environment variables for the command as options to sudo, in the form VAR=value. For example: LD_LIBRARY_PATH=/usr/local/pkg/lib. These might be subject to restrictions from the security policy plugin โจ The sudoers policy treats environment variables passed as options the same way as existing environment variables, with one important difference. If the setenv option is set in sudoers, and the command to be run has the SETENV tag set or the matched command is ALL, you can set variables that would otherwise be forbidden ๐ See sudoers(5) for more info.
โจ COMMAND EXECUTION โจ
okay so when sudo runs a command, the security policy decides the execution environment ๐
Usually the real and effective user and group IDs get set to match the target user from the password database, and the group vector gets set up from the group database (unless you passed -P) ๐ซถ
the security policy can set any of these for the command:
- real and effective user-ID ๐
- real and effective group-ID ๐
- supplementary group-IDs ๐
- the environment list ๐ธ
- current working directory ๐
- file creation mode mask (umask) ๐ฆ
- SELinux role and type ๐ฅ
- scheduling priority (aka nice value) โญ
โจ Process model โจ
there are two distinct ways sudo can run a command, bestie ๐ง
if an I/O logging plugin is set up to log terminal I/O, or the security policy explicitly asks for it, sudo allocates a new pseudo-terminal (โptyโ) and calls fork(2) to make a second sudo process called the monitor ๐ the monitor creates a new terminal session where it's the leader and the pty is its controlling terminal, calls fork(2) again, sets up the execution environment as described above, and then uses the execve(2) system call to run the command in the child process ๐ฆ the monitor exists to relay job control signals between your terminal and the pty the command runs in, so you can suspend and resume the command like normal ๐ without it, the command would be in what POSIX calls an โorphaned process groupโ and it would not get any job control signals from the kernel ๐ when the command exits or gets killed by a signal, the monitor passes the exit status up to the main sudo process and exits. then the main sudo process passes the exit status to the security policy's close function, plus the close function of any configured audit plugin, and exits ๐ this mode is the default for sudo versions 1.9.14 and above when using the sudoers policy ๐
if no pty is used, sudo calls fork(2), sets up the execution environment as described above, and uses execve(2) to run the command in the child process ๐ธ the main sudo process waits until the command finishes, then passes the exit status to the security policy's close function, plus the close function of any configured audit plugins, and exits โจ as a special case, if the policy plugin doesn't define a close function, sudo just executes the command directly instead of calling fork(2) first ๐ the sudoers policy plugin only defines a close function when I/O logging is enabled, a pty is required, an SELinux role is specified, the command has an associated timeout, or the pam_session or pam_setcred options are enabled. both pam_session and pam_setcred are enabled by default on systems using PAM ๐ซถ this mode is the default for sudo versions prior to 1.9.14 when using the sudoers policy ๐
on systems that use PAM, the security policy's close function is responsible for closing the PAM session ๐ it may also log the command's exit status ๐
โจ Signal handling โจ
when the command runs as a child of the sudo process, sudo relays any signals it receives over to the command ๐ก SIGINT and SIGQUIT only get relayed when the command is running in a new pty, or when the signal was sent by a user process and not the kernel. this stops the command from getting SIGINT twice every time you hit control-C ๐ some signals, like SIGSTOP and SIGKILL, can't be caught, so they won't be relayed to the command ๐ as a general rule, use SIGTSTP instead of SIGSTOP when you want to suspend a command being run by sudo ๐
as a special case, sudo won't relay signals that were sent by the command it's running. this stops the command from accidentally killing itself ๐ญ on some systems, the reboot(8) utility sendsSIGTERMto all non-system processes other than itself before rebooting the system. this keeps sudo from relaying theSIGTERMit received back to reboot(8), which might then exit before the system was actually rebooted, leaving it in a half-dead state similar to single user mode ๐ heads up though, this check only applies to the command run by sudo and not to any other processes that command may create. so running a script that calls reboot(8) or shutdown(8) via sudo may leave the system in this undefined state, unless reboot(8) or shutdown(8) are run using theexec()family of functions instead ofsystem()(which puts a shell between the command and the calling process) โ ๏ธ
โจ Plugins โจ
plugins can be specified with Plugin directives in the sudo.conf(5) file ๐งฉ they may be loaded as dynamic shared objects (on systems that support them), or compiled directly into the sudo binary. if there's no sudo.conf(5) file, or it doesn't have any Plugin lines, sudo uses sudoers(5) for the policy, auditing, and I/O logging plugins ๐ check the sudo.conf(5) manual for details on the /etc/sudo.conf file, and the sudo_plugin(5) manual for more info about the sudo plugin architecture ๐
โจ EXIT VALUE โจ
okay this part is so important ๐ฅบ if a command runs successfully, the exit status from sudo is the exit status of the program that was executed ๐ฏ if the command died from a signal, sudo sends itself the same signal that killed the command ๐
if you use the -l option without a command, sudo exits with 0 if you're allowed to run sudo and you authenticated successfully (as the security policy requires) โ
if a command is given with -l, the exit value is only 0 if the security policy permits that command. otherwise it's 1 ๐
โโ๏ธ
if there's an authentication failure, a configuration or permission problem, or the given command can't be executed, sudo exits with 1 ๐ญ in that last case, the error string gets printed to standard error. if sudo can't stat(2) one or more entries in your PATH, an error gets printed to standard error too. (if the directory doesn't exist or isn't really a directory, the entry gets ignored and no error is printed ๐) this shouldn't happen under normal circumstances โจ the most common reason stat(2) returns โpermission deniedโ is if you're running an automounter and one of the directories in your PATH lives on a machine that's currently unreachable ๐
โจ SECURITY NOTES โจ
sudo really tries to be safe when it executes external commands ๐ก๏ธ
to prevent command spoofing, sudo checks "." and "" (both mean the current directory) last when it searches for a command in your PATH (if one or both are in there) ๐ต๏ธโโ๏ธ depending on the security policy, your PATH environment variable may be modified, replaced, or passed through unchanged to the program sudo runs ๐ซง
never give someone sudo privileges to run files that are writable by them, or that live in a directory they can write to ๐ซ if the user can modify or replace the command, there's no way to limit what other commands they can run ๐
by default, sudo only logs the command it explicitly runs. if someone runs a command like sudo su or sudo sh, any commands run from that shell aren't subject to sudo's security policy ๐ฑ the same goes for commands that offer shell escapes (including most editors) ๐ if I/O logging is enabled, those subsequent commands will have their input and/or output logged, but there won't be traditional logs for them. so be careful when you give users access to commands via sudo, and check that the command won't accidentally give them an effective root shell ๐ for ways to handle this, see the Preventing shell escapes section in sudoers(5) ๐
to protect potentially sensitive info, sudo disables core dumps by default while it's running (they get re-enabled for the command that runs) ๐ this is a historical practice from a time when most operating systems let set-user-ID processes dump core by default ๐ฆ if you want to debug sudo crashes, you can re-enable core dumps by setting "disable_coredump" to false in the sudo.conf(5) file like this ๐ง
Set disable_coredump false
see the sudo.conf(5) manual for more info ๐ซถ ๐
โจ ENVIRONMENT โจ
okay so sudo reads and sets a bunch of environment variables ๐ธ but bestie, the security policy is the one with the final say on what the command's environment actually looks like ๐
EDITORโ the default editor for-e(sudoedit) mode, but only if neitherSUDO_EDITORnorVISUALis set ๐MAILโ gets set to the mail spool of the target user when you pass-i, or whenenv_resetis on in sudoers. (UnlessMAILis in theenv_keeplist, then it stays put ๐ซถ)HOMEโ gets set to the target user's home directory when you use-ior-H, when you use-sandset_homeis set in sudoers, whenalways_set_homeis enabled in sudoers, or whenenv_resetis enabled in sudoers andHOMEisn't in theenv_keeplist ๐กLOGNAMEโ gets set to the target user's login name when you use-i, when theset_lognameoption is enabled in sudoers, or when theenv_resetoption is enabled in sudoers (unlessLOGNAMEis inenv_keep) ๐PATHโ the security policy is allowed to override this one ๐ฆSHELLโ used to figure out which shell to run with the-soption ๐SUDO_ASKPASSโ the path to a helper program that reads the password when there's no terminal around, or when you pass the-Aoption ๐SUDO_COMMANDโ gets set to the command sudo ran, args included. The args get chopped off at 4096 characters to prevent a potential execution error ๐SUDO_EDITORโ the default editor for-e(sudoedit) mode ๐SUDO_GIDโ the group-ID of the person who invoked sudo ๐SUDO_HOMEโ the home directory of the person who invoked sudo ๐SUDO_PROMPTโ the default password prompt, unless you used the-poption ๐SUDO_PS1โ if this is set,PS1gets set to its value for the program being run โญSUDO_TTYโ the terminal device of the person who invoked sudo, if there is one ๐ฅ๏ธSUDO_UIDโ the user-ID of the person who invoked sudo ๐งSUDO_USERโ the login name of the person who invoked sudo ๐USERโ set to the same value asLOGNAME, which we just covered ๐ซงVISUALโ the default editor for-e(sudoedit) mode, but only ifSUDO_EDITORisn't set ๐ท
โจ FILES โจ
okay this one's short and sweet ๐ฌ
/etc/sudo.confโ the sudo front-end configuration ๐ง
โจ EXAMPLES โจ
these examples assume your security policy is properly configured, so make sure that's sorted before you try them ๐ซถ
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 that only root and the users in the adm group can access:
$ 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. The commands run in a sub-shell so that the โcdโ command and file redirection can actually work ๐ง
$ sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
โจ DIAGNOSTICS โจ
here are the error messages sudo might throw at you, so you know what's going on when it happens ๐
Error messages produced by sudo include:
editing files in a writable directory is not permitted
by default, sudoedit won't let you edit a file when any of the parent directories are writable by the user who invoked it. This avoids a race condition that could let the user overwrite an arbitrary file ๐ซ. See the sudoedit_checkdir option in sudoers(5) for more information.
editing symbolic links is not permitted
by default, sudoedit doesn't follow symbolic links when it opens files ๐. See the sudoedit_follow option in sudoers(5) for more information.
effective uid is not 0, is sudo installed setuid root?
sudo wasn't run with root privileges. The sudo binary has to be owned by the root user and have the set-user-ID bit set. It also can't be located on a file system mounted with the โnosuidโ option, or on an NFS file system that maps uid 0 to an unprivileged uid ๐ค
effective uid is not 0, is sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
sudo wasn't run with root privileges. The sudo binary has the right owner and permissions, but it still didn't run as root anyway ๐ญ. The most common reason is that the file system the sudo binary lives on is mounted with the โnosuidโ option, or it's an NFS file system that maps uid 0 to an unprivileged uid.
fatal error, unable to load plugins
an error happened while loading or initializing the plugins specified in sudo.conf(5) ๐
invalid environment variable name
one or more environment variable names you passed via the -E option had an equal sign (โ=โ) in them. The arguments to -E should just be environment variable names, without any value attached ๐
โโ๏ธ
no password was provided
when sudo tried to read the password, it didn't get any characters. This can happen when there's no terminal available (or you used the -S option) and standard input got redirected from /dev/null ๐ณ๏ธ
a terminal is required to read the password
sudo needs to read the password, but there's no mechanism available to do it. Remote commands run via ssh(1) don't have a terminal by default, but passing the -t option to ssh(1) makes it allocate one, which should let sudo read the password ๐ป. To let sudo run local commands without a terminal, you can use the -S option to read the password from standard input, or configure an askpass helper either through the sudo.conf(5) file or by setting the SUDO_ASKPASS environment variable ๐.
no writable temporary directory found
sudoedit couldn't find a usable temporary directory to store its intermediate files ๐
The โno new privilegesโ flag is set, which prevents sudo from running as root.
sudo was run by a process that has the Linux โno new privilegesโ flag set. This makes the set-user-ID bit get ignored when running an executable, which stops sudo from working. The most likely cause is running sudo inside a container that sets this flag. Check the container's documentation to see if you can configure it so the flag isn't set ๐ฆ
sudo must be owned by uid 0 and have the setuid bit set
sudo wasn't run with root privileges. The sudo binary doesn't have the correct owner or permissions. It has to be owned by the root user and have the set-user-ID bit set ๐ ๏ธ
sudoedit is not supported on this platform
sudoedit only works on systems that support setting the effective user-ID ๐
timed out reading password
you didn't enter a password before the password timeout expired. That's 5 minutes by default โฐ
you do not exist in the passwd database
your user-ID doesn't show up in the system passwd database ๐ป
you may not specify environment variables in edit mode
you can only specify environment variables when you're running a command. When you're editing a file, the editor runs with your environment left completely unmodified ๐
โจ SEE ALSO โจ
if you want to keep going, check these out ๐ฆ
su(1)stat(2)login_cap(3)passwd(5)sudo.conf(5)sudo_plugin(5)sudoers(5)sudoers_timestamp(5)sudoreplay(8)visudo(8)
โจ HISTORY โจ
for a brief history of sudo, check out the HISTORY.md file in the sudo distribution, at https://www.sudo.ws/about/history/ ๐
โจ AUTHORS โจ
so many people have worked on sudo over the years ๐ซถ this version is made up of code written mainly by:
Todd C. Miller ๐
For an exhaustive list of everyone who's contributed to sudo, see the CONTRIBUTORS.md file in the sudo distribution, at https://www.sudo.ws/about/contributors/ ๐
โจ CAVEATS โจ
okay real talk, these are the things you need to be careful about ๐ซฃ
There is no easy way to stop a user from getting a root shell if that user is allowed to run arbitrary commands via sudo ๐ฌ. Also, lots of programs (like editors) let you run commands through shell escapes, which means you can skip sudo's checks entirely. That said, on most systems you can block shell escapes with the noexec functionality in the sudoers(5) plugin ๐.
It's not meaningful to run the โcdโ command directly via sudo, bestie, like this:
$ sudo cd /usr/local/protected
because when the command exits, the parent process (your shell) is still in the same directory it was before ๐. The -D option can be used to run a command in a specific directory instead.
Running shell scripts via sudo can expose the same kernel bugs that make set-user-ID shell scripts unsafe on some operating systems. (If your OS has a /dev/fd/ directory, set-user-ID shell scripts are generally safe ๐ซง.)
โจ BUGS โจ
if you think you've found a bug in sudo, you can either file a report in the sudo bug database at https://bugzilla.sudo.ws/, or open an issue at https://github.com/sudo-project/sudo/issues ๐. If you'd rather use email, you can send messages to the sudo-workers mailing list at https://www.sudo.ws/mailman/listinfo/sudo-workers (public), or to <sudo@sudo.ws> (private) ๐.
๐จ Please do NOT report security vulnerabilities through public GitHub issues, Bugzilla, or mailing lists! Instead, email them to<Todd.Miller@sudo.ws>. You can encrypt your message with PGP if you'd like, using the key found athttps://www.sudo.ws/dist/PGPKEYS๐
โจ SUPPORT โจ
you can get limited free support through the sudo-users mailing list. Check https://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or to search the archives ๐ฌ
โจ DISCLAIMER โจ
sudo is provided โAS ISโ, and any express or implied warranties, including but not limited to the implied warranties of merchantability and fitness for a particular purpose, are disclaimed ๐
. For complete details, see the LICENSE.md file distributed with sudo, or https://www.sudo.ws/about/license/ ๐
That's a wrap on the sudo manual, bestie! ๐ You made it through the whole thing, and honestly? Iconic behaviour ๐ โจ Go touch grass, then go sudo responsibly ๐ซถ๐ธ
๐ฆ where this page comes from
- ubuntu questing: sudo 1.9.17p2-1ubuntu1
- ubuntu questing: sudo 1.9.17p2-1ubuntu1.1 ยท ISC
- ubuntu resolute: sudo 1.9.17p2-1ubuntu3 ยท ISC
- ubuntu resolute: sudo 1.9.17p2-1ubuntu3.2 ยท ISC
- ubuntu stonking: sudo 1.9.17p2-7ubuntu5 ยท ISC
- ๐ the page's license: ISC
- Copyright (c) 1994-1996, 1998-2005, 2007-2025 Todd C. Miller <Todd.Miller@sudo.ws>
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms