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:
visudolocks 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
eto re-edit the sudoers file - type
xto exit without saving the changes - type
Qto quit and save changes
โ ๏ธ theQoption should be used with extreme caution โ because ifvisudobelieves there to be a syntax error, so willsudo. 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:visudois typically run as root, so this option may allow a user withvisudoprivileges 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,visudowill also check the file ownership and permissions (see the-Oand-Poptions). a message will be printed to the standard output describing the status of sudoers unless the-qoption was specified. if the check completes successfully,visudowill exit with a value of0. if an error is encountered,visudowill exit with a value of1. โญ-f sudoers,--file=sudoersโ specify an alternate sudoers file location, see below. as of version1.8.27, the sudoers path can be specified without using the-foption. 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,visudowill edit the main sudoers file and any files included via@includeor#includedirectives. files included via@includediror#includedirare 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-coption. 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,visudowill 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 thevisudoand 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 byvisudoas the editor to useVISUALโ used byvisudoifSUDO_EDITORis not setEDITORโ used byvisudoif neitherSUDO_EDITORnorVISUALis 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 byvisudo
๐ 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 runvisudoas 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}_Aliasor 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 (sudowill 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}_Aliaswas 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}_Aliasincludes 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 unlessvisudois run in-s(strict) mode, assudowill ignore cycles when parsing the sudoers file. round and round we go ๐ignoring editor backup fileโ while processing a@includediror#includedir, a file was found with a name that ends in~or.bak. such files are skipped bysudoandvisudo. not today, backup file ๐ignoring file name containing '.'โ while processing a@includediror#includedir, a file was found with a name that contains a.character. such files are skipped bysudoandvisudo. dots are not invited to this party ๐ซunknown defaults entry "name"โ the sudoers file contains aDefaultssetting not recognized byvisudo. 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:
- file a bug report in the sudo bug database at
https://bugzilla.sudo.ws/ - or open an issue at
https://github.com/sudo-project/sudo/issues - or, if email is more your vibe, you can send messages to the sudo-workers mailing list at
https://www.sudo.ws/mailman/listinfo/sudo-workers(that one's public) ๐ - or go straight to
<sudo@sudo.ws>(that one's private, iykyk) ๐
๐จ 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 athttps://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
- alpine 3.24: sudo-doc 1.9.17_p2-r2 ยท custom ISC
- centos-stream 10: sudo 1.9.17-13.p2.el10 ยท ISC
- ๐ the page's license: ISC
- Copyright (c) 1996,1998-2005, 2007-2023 Todd C. Miller <Todd.Miller@sudo.ws>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms