VISUDO(8)

๐Ÿ’… VISUDO(8) ๐Ÿ’… โ€” edit the sudoers file

okay so real talk, bestie: this is visudo(8) from the System Manager's Manual and it's genuinely one of the most important pages you'll ever read, because it's the thing standing between you and a completely bricked sudo setup. no cap. ๐Ÿซถ

โœจ NAME โœจ

visudo โ€” edit the sudoers file. that's it. that's the whole gig. but the way she does it?? iconic. ๐Ÿ‘‘

๐ŸŒธ SYNOPSIS ๐ŸŒธ

visudo [-chIOPqsV] [[-f] sudoers]

๐Ÿ’– DESCRIPTION ๐Ÿ’–

visudo edits the sudoers file in a safe fashion, analogous to vipw(8). she's the responsible older sibling of editors, fr fr.

here's the slay list of what she does:

  • visudo locks the sudoers file against multiple simultaneous edits โ€” no two people editing at once, we don't do chaos here ๐Ÿ’…
  • she performs basic validity checks
  • she checks for syntax errors before installing the edited file
  • if the sudoers file is currently being edited, you will receive a message to try again later (patience, bestie, patience ๐Ÿงš)

if the sudoers file does not exist, it will be created โ€” unless the editor exits without writing to the file. so like, if you open it and immediately bail, nothing happens. respectful.

visudo parses the sudoers file after editing and will not save the changes if there's a syntax error. upon finding an error, visudo will print a message stating the line number(s) where the error occurred, and you'll get the โ€œWhat now?โ€ prompt. at this point you've got options, main character decisions:

  • type e to re-edit the sudoers file
  • type x to exit without saving the changes
  • type Q to quit and save changes
โš ๏ธ the Q option should be used with extreme caution โ€” because if visudo believes there to be a syntax error, so will sudo. like, you are both gonna have the same opinion. it's giving "we both saw the same thing and we both hate it."

if e is typed to edit the sudoers file after a syntax error has been detected, the cursor will be placed on the line where the error occurred (if the editor supports this feature). so convenient. obsessed. โœจ

there are two sudoers settings that determine which editor visudo will run. let's meet them ๐ŸŽ€

๐Ÿฆ‹ editor

a colon (:) separated list of editors allowed to be used with visudo. visudo will choose the editor that matches the user's SUDO_EDITOR, VISUAL, or EDITOR environment variable if possible, or the first editor in the list that exists and is executable.

sudo does not preserve the SUDO_EDITOR, VISUAL, or EDITOR environment variables unless they are present in the env_keep list or the env_reset option is disabled in the sudoers file.

the default editor path is /usr/bin/vi, which can be set at compile time via the --with-editor configure option.

๐Ÿฆ‹ env_editor

if set, visudo will use the value of the SUDO_EDITOR, VISUAL, or EDITOR environment variables before falling back on the default editor list.

๐Ÿšจ okay big warning time: visudo is typically run as root, so this option may allow a user with visudo privileges to run arbitrary commands as root without logging. yes. that's as scary as it sounds. ๐Ÿ˜ญ

an alternative is to place a colon-separated list of โ€œsafeโ€ editors in the editor variable. visudo will then only use SUDO_EDITOR, VISUAL, or EDITOR if they match a value specified in editor.

if the env_reset flag is enabled, the SUDO_EDITOR, VISUAL, and/or EDITOR environment variables must be present in the env_keep list for the env_editor flag to function when visudo is invoked via sudo.

the default value is on, which can be set at compile time via the --with-env-editor configure option.


๐ŸŽ€ The options are as follows ๐ŸŽ€

  • -c, --check โ€” enable check-only mode. the existing sudoers file (and any other files it includes) will be checked for syntax errors. if the path to the sudoers file was not specified, visudo will also check the file ownership and permissions (see the -O and -P options). a message will be printed to the standard output describing the status of sudoers unless the -q option was specified. if the check completes successfully, visudo will exit with a value of 0. if an error is encountered, visudo will exit with a value of 1. โญ
  • -f sudoers, --file=sudoers โ€” specify an alternate sudoers file location, see below. as of version 1.8.27, the sudoers path can be specified without using the -f option. glow-up fr ๐Ÿ’…
  • -h, --help โ€” display a short help message to the standard output and exit. short king behavior, we respect it.
  • -I, --no-includes โ€” disable the editing of include files unless there is a pre-existing syntax error. by default, visudo will edit the main sudoers file and any files included via @include or #include directives. files included via @includedir or #includedir are never edited unless they contain a syntax error. ๐Ÿ™ˆ
  • -O, --owner โ€” enforce the default ownership (user and group) of the sudoers file. in edit mode, the owner of the edited file will be set to the default. in check mode (-c), an error will be reported if the owner is incorrect. this option is enabled by default if the sudoers file was not specified. ๐Ÿซถ
  • -P, --perms โ€” enforce the default permissions (mode) of the sudoers file. in edit mode, the permissions of the edited file will be set to the default. in check mode (-c), an error will be reported if the file permissions are incorrect. this option is enabled by default if the sudoers file was not specified. ๐Ÿ”ฅ
  • -q, --quiet โ€” enable quiet mode. in this mode details about syntax errors are not printed. this option is only useful when combined with the -c option. shhh. ๐Ÿคซ
  • -s, --strict โ€” enable strict checking of the sudoers file. if an alias is referenced but not actually defined, or if there is a cycle in an alias, visudo will consider this a syntax error. it is not possible to differentiate between an alias and a host name or user name that consists solely of uppercase letters, digits, and the underscore (_) character. ๐Ÿง
  • -V, --version โ€” print the visudo and sudoers grammar versions and exit. version check era ๐Ÿ’œ

a sudoers file may be specified instead of the default, /etc/sudoers. the temporary file used is the specified sudoers file with โ€œ.tmpโ€ appended to it.

in check-only mode only, - may be used to indicate that sudoers will be read from the standard input. ๐Ÿ“

โš ๏ธ because the policy is evaluated in its entirety, it is not sufficient to check an individual sudoers include file for syntax errors. the whole vibe has to be checked, not just one lil piece.

๐ŸŒˆ Debugging and sudoers plugin arguments ๐ŸŒˆ

visudo versions 1.8.4 and higher support a flexible debugging framework that is configured via Debug lines in the sudo.conf(5) file.

starting with sudo 1.8.12, visudo will also parse the arguments to the sudoers plugin to override the default sudoers path name, user-ID, group-ID, and file mode. these arguments, if present, should be listed after the path to the plugin (i.e., after sudoers.so). multiple arguments may be specified, separated by white space. for example:

Plugin sudoers_policy sudoers.so sudoers_mode=0400

the following arguments are supported:

โญ sudoers_file=pathname

the sudoers_file argument can be used to override the default path to the sudoers file.

โญ sudoers_uid=user-ID

the sudoers_uid argument can be used to override the default owner of the sudoers file. it should be specified as a numeric user-ID.

โญ sudoers_gid=group-ID

the sudoers_gid argument can be used to override the default group of the sudoers file. it must be specified as a numeric group-ID (not a group name). read that again bestie, numeric only ๐Ÿ’€

โญ sudoers_mode=mode

the sudoers_mode argument can be used to override the default file mode for the sudoers file. it should be specified as an octal value.

for more information on configuring sudo.conf(5), refer to its manual.

๐ŸŒธ ENVIRONMENT ๐ŸŒธ

the following environment variables may be consulted depending on the value of the editor and env_editor sudoers settings:

  • SUDO_EDITOR โ€” invoked by visudo as the editor to use
  • VISUAL โ€” used by visudo if SUDO_EDITOR is not set
  • EDITOR โ€” used by visudo if neither SUDO_EDITOR nor VISUAL is set

it's a whole fallback chain and honestly? she's organized. ๐Ÿ’…

๐ŸŽ€ FILES ๐ŸŽ€

  • /etc/sudo.conf โ€” Sudo front-end configuration
  • /etc/sudoers โ€” List of who can run what
  • /etc/sudoers.tmp โ€” Default temporary file used by visudo

๐Ÿ’€ DIAGNOSTICS ๐Ÿ’€

in addition to reporting sudoers syntax errors, visudo may produce the following messages:

  • sudoers file busy, try again later. โ€” someone else is currently editing the sudoers file. it's not you, it's them. wait your turn ๐Ÿซถ
  • /etc/sudoers: Permission denied โ€” you didn't run visudo as root. bestie. come on. ๐Ÿ˜ญ
  • you do not exist in the passwd database โ€” your user-ID does not appear in the system passwd database. ghost era ๐Ÿ‘ป
  • Warning: {User,Runas,Host,Cmnd}_Alias referenced but not defined โ€” either you are trying to use an undeclared {User,Runas,Host,Cmnd}_Alias or you have a user or host name listed that consists solely of uppercase letters, digits, and the underscore (_) character. in the latter case, you can ignore the warnings (sudo will not complain). the message is prefixed with the path name of the sudoers file and the line number where the undefined alias was used. in -s (strict) mode these are errors, not warnings. ๐Ÿ”ฅ
  • Warning: unused {User,Runas,Host,Cmnd}_Alias โ€” the specified {User,Runas,Host,Cmnd}_Alias was defined but never used. the message is prefixed with the path name of the sudoers file and the line number where the unused alias was defined. you may wish to comment out or remove the unused alias. she's just sitting there. unused. neglected. ๐Ÿ™ˆ
  • Warning: cycle in {User,Runas,Host,Cmnd}_Alias โ€” the specified {User,Runas,Host,Cmnd}_Alias includes a reference to itself, either directly or through an alias it includes. the message is prefixed with the path name of the sudoers file and the line number where the cycle was detected. this is only a warning unless visudo is run in -s (strict) mode, as sudo will ignore cycles when parsing the sudoers file. round and round we go ๐ŸŒ€
  • ignoring editor backup file โ€” while processing a @includedir or #includedir, a file was found with a name that ends in ~ or .bak. such files are skipped by sudo and visudo. not today, backup file ๐Ÿ’…
  • ignoring file name containing '.' โ€” while processing a @includedir or #includedir, a file was found with a name that contains a . character. such files are skipped by sudo and visudo. dots are not invited to this party ๐Ÿšซ
  • unknown defaults entry "name" โ€” the sudoers file contains a Defaults setting not recognized by visudo. who is she. where did she come from. ๐Ÿง

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

vi(1), sudo.conf(5), sudoers(5), sudo(8), vipw(8)

๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

many people have worked on sudo over the years; this version consists of code written primarily by:

      Todd C. Miller

see the CONTRIBUTORS.md file in the sudo distribution (https://www.sudo.ws/about/contributors/) for an exhaustive list of people who have contributed to sudo. legends, all of them. ๐Ÿซถ

โš ๏ธ CAVEATS โš ๏ธ

there is no easy way to prevent a user from gaining a root shell if the editor used by visudo allows shell escapes. like, that's just the situation. no cap. ๐Ÿ’€

๐Ÿ› BUGS ๐Ÿ›

okay so if you genuinely think you found a bug in visudo, bestie, you have options and honestly that's so valid of you:

๐Ÿšจ HUGE one, do not skip this: please do NOT report security vulnerabilities through public GitHub issues, Bugzilla, or mailing lists. That is not the move, fr fr. Instead, report them via email to <Todd.Miller@sudo.ws>. You may encrypt your message with PGP if you'd like โ€” the key is right there at https://www.sudo.ws/dist/PGPKEYS. ๐Ÿ”โœจ

๐Ÿซถ SUPPORT ๐Ÿซถ

Limited free support is available via the sudo-users mailing list, and yes it's giving community-coded in the best way. Head to https://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or to search the archives (the archives are lowkey a whole library, ngl ๐Ÿ“š).


๐Ÿ’€ DISCLAIMER ๐Ÿ’€

visudo 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. Yep, the classic legal-ese, no cap. ๐Ÿ˜ญ

For the complete details, see the LICENSE.md file distributed with sudo, or the version online at https://www.sudo.ws/about/license/. ๐Ÿ“„


โœจ and that's the whole page, bestie! โœจ

This one's from Sudo 1.9.17p2, dated July 27, 2023, and it's VISUDO(8) โ€” go edit your sudoers file responsibly, stay gorgeous, and remember: always let visudo check your syntax before you commit ๐ŸŽ€๐Ÿฆ‹๐Ÿ’…

๐Ÿ“ฆ where this page comes from