{
    "mode": "man",
    "parameter": "visudo",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/visudo/8/json",
    "generated": "2026-11-08T01:23:23Z",
    "synopsis": "visudo [-chIOPqsV] [[-f] sudoers]",
    "sections": {
        "NAME": {
            "content": "visudo — edit the sudoers file\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "visudo [-chIOPqsV] [[-f] sudoers]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "visudo  edits  the  sudoers  file  in a safe fashion, analogous to vipw(8).  visudo locks the\nsudoers file against multiple simultaneous edits, performs basic validity checks, and  checks\nfor  syntax errors before installing the edited file.  If the sudoers file is currently being\nedited you will receive a message to try again later.\n\nIf the sudoers file does not exist, it will be created unless the editor exits without  writ‐\ning to the file.\n\nvisudo parses the sudoers file after editing and will not save the changes if there is a syn‐\ntax  error.   Upon  finding  an error, visudo will print a message stating the line number(s)\nwhere the error occurred and the user will receive the “What now?” prompt.  At this point the\nuser may enter ‘e’ to re-edit the sudoers file, ‘x’ to exit without saving  the  changes,  or\n‘Q’  to quit and save changes.  The ‘Q’ option should be used with extreme caution because if\nvisudo believes there to be a syntax error, so will sudo.   If  ‘e’  is  typed  to  edit  the\nsudoers  file  after  a syntax error has been detected, the cursor will be placed on the line\nwhere the error occurred (if the editor supports this feature).\n\nThere are two sudoers settings that determine which editor visudo will run.\n\neditor      A colon (‘:’) separated list of editors allowed to be used with  visudo.   visudo\nwill choose the editor that matches the user's SUDOEDITOR, VISUAL, or EDITOR en‐\nvironment  variable  if possible, or the first editor in the list that exists and\nis executable.  sudo does not preserve the SUDOEDITOR, VISUAL, or  EDITOR  envi‐\nronment  variables  unless they are present in the envkeep list or the envreset\noption  is  disabled  in  the  sudoers  file.   The  default   editor   path   is\n/usr/bin/editor  which can be set at compile time via the --with-editor configure\noption.\n\nenveditor  If set, visudo will use the value of the SUDOEDITOR, VISUAL, or EDITOR  environ‐\nment  variables  before falling back on the default editor list.  visudo is typi‐\ncally run as root so this option may allow a user with visudo privileges  to  run\narbitrary  commands as root without logging.  An alternative is to place a colon-\nseparated list of “safe” editors in the editor variable.  visudo will  then  only\nuse SUDOEDITOR, VISUAL, or EDITOR if they match a value specified in editor.  If\nthe envreset flag is enabled, the SUDOEDITOR, VISUAL, and/or EDITOR environment\nvariables  must  be present in the envkeep list for the enveditor flag to func‐\ntion when visudo is invoked via sudo.  The default value is on, which can be  set\nat compile time via the --with-env-editor configure option.\n\nThe options are as follows:\n",
            "subsections": [
                {
                    "name": "-c --check",
                    "content": "Enable  check-only mode.  The existing sudoers file (and any other files it includes)\nwill be checked for syntax errors.  If the path to the sudoers file  was  not  speci‐\nfied,  visudo  will  also check the file ownership and permissions (see the -O and -P\noptions).  A message will be printed to the standard output describing the status  of\nsudoers  unless  the  -q  option was specified.  If the check completes successfully,\nvisudo will exit with a value of 0.  If an error is  encountered,  visudo  will  exit\nwith a value of 1.\n",
                    "flag": "-c",
                    "long": "--check"
                },
                {
                    "name": "-f _ --file",
                    "content": "Specify  an  alternate  sudoers  file location, see below.  As of version 1.8.27, the\nsudoers path can be specified without using the -f option.\n",
                    "flag": "-f",
                    "long": "--file"
                },
                {
                    "name": "-h --help",
                    "content": "Display a short help message to the standard output and exit.\n",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-I --no-includes",
                    "content": "Disable the editing of include files unless there is a pre-existing syntax error.  By\ndefault, visudo will edit the main sudoers file and any files included  via  @include\nor  #include  directives.   Files  included  via @includedir or #includedir are never\nedited unless they contain a syntax error.\n",
                    "flag": "-I",
                    "long": "--no-includes"
                },
                {
                    "name": "-O --owner",
                    "content": "Enforce the default ownership (user and group) of the sudoers file.   In  edit  mode,\nthe  owner of the edited file will be set to the default.  In check mode (-c), an er‐\nror will be reported if the owner is incorrect.  This option is enabled by default if\nthe sudoers file was not specified.\n",
                    "flag": "-O",
                    "long": "--owner"
                },
                {
                    "name": "-P --perms",
                    "content": "Enforce the default permissions (mode) of the sudoers file.  In edit mode,  the  per‐\nmissions of the edited file will be set to the default.  In check mode (-c), an error\nwill  be  reported  if the file permissions are incorrect.  This option is enabled by\ndefault if the sudoers file was not specified.\n",
                    "flag": "-P",
                    "long": "--perms"
                },
                {
                    "name": "-q --quiet",
                    "content": "Enable quiet mode.  In this mode details about syntax errors are not  printed.   This\noption is only useful when combined with the -c option.\n",
                    "flag": "-q",
                    "long": "--quiet"
                },
                {
                    "name": "-s --strict",
                    "content": "Enable  strict checking of the sudoers file.  If an alias is referenced but not actu‐\nally defined or if there is a cycle in an alias, visudo will consider this  a  syntax\nerror.   It is not possible to differentiate between an alias and a host name or user\nname that consists solely of uppercase letters,  digits,  and  the  underscore  (‘’)\ncharacter.\n",
                    "flag": "-s",
                    "long": "--strict"
                },
                {
                    "name": "-V --version",
                    "content": "Print the visudo and sudoers grammar versions and exit.\n\nA  sudoers  file  may  be specified instead of the default, /etc/sudoers.  The temporary file\nused is the specified sudoers file with “.tmp” appended to it.  In check-only mode only,  ‘-’\nmay  be used to indicate that sudoers will be read from the standard input.  Because the pol‐\nicy is evaluated in its entirety, it is not sufficient to check an individual sudoers include\nfile for syntax errors.\n",
                    "flag": "-V",
                    "long": "--version"
                },
                {
                    "name": "Debugging and sudoers plugin arguments",
                    "content": "visudo versions 1.8.4 and higher support a flexible debugging framework  that  is  configured\nvia Debug lines in the sudo.conf(5) file.\n\nStarting  with  sudo  1.8.12,  visudo  will also parse the arguments to the sudoers plugin to\noverride the default sudoers path name, user-ID, group-ID, and file mode.   These  arguments,\nif present, should be listed after the path to the plugin (i.e., after sudoers.so).  Multiple\narguments may be specified, separated by white space.  For example:\n\nPlugin sudoerspolicy sudoers.so sudoersmode=0400\n\nThe following arguments are supported:\n\nsudoersfile=pathname\nThe sudoersfile argument can be used to override the default path to the sudoers file.\n\nsudoersuid=user-ID\nThe sudoersuid argument can be used to override the default owner of the sudoers file.\nIt should be specified as a numeric user-ID.\n\nsudoersgid=group-ID\nThe sudoersgid argument can be used to override the default group of the sudoers file.\nIt must be specified as a numeric group-ID (not a group name).\n\nsudoersmode=mode\nThe sudoersmode argument can be used to override the default file mode for the sudoers\nfile.  It should be specified as an octal value.\n\nFor more information on configuring sudo.conf(5), refer to its manual.\n"
                }
            ]
        },
        "ENVIRONMENT": {
            "content": "The following environment variables may be consulted depending on the value of the editor and\nenveditor sudoers settings:\n\nSUDOEDITOR      Invoked by visudo as the editor to use\n\nVISUAL           Used by visudo if SUDOEDITOR is not set\n\nEDITOR           Used by visudo if neither SUDOEDITOR nor VISUAL is set\n",
            "subsections": []
        },
        "FILES": {
            "content": "/etc/sudo.conf            Sudo front-end configuration\n\n/etc/sudoers              List of who can run what\n\n/etc/sudoers.tmp          Default temporary file used by visudo\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "In addition to reporting sudoers syntax errors, visudo may produce the following messages:\n",
            "subsections": [
                {
                    "name": "sudoers file busy, try again later.",
                    "content": "Someone else is currently editing the sudoers file.\n"
                },
                {
                    "name": "/etc/sudoers: Permission denied",
                    "content": "You didn't run visudo as root.\n"
                },
                {
                    "name": "you do not exist in the passwd database",
                    "content": "Your user-ID does not appear in the system passwd database.\n"
                },
                {
                    "name": "Warning: {User,Runas,Host,Cmnd}_Alias referenced but not defined",
                    "content": "Either  you  are trying to use an undeclared {User,Runas,Host,Cmnd}Alias or you have a\nuser or host name listed that consists solely of uppercase letters, digits, and the un‐\nderscore (‘’) character.  In the latter case, you can ignore the warnings  (sudo  will\nnot  complain).  The message is prefixed with the path name of the sudoers file and the\nline number where the undefined alias was used.  In -s (strict) mode these are  errors,\nnot warnings.\n"
                },
                {
                    "name": "Warning: unused {User,Runas,Host,Cmnd}_Alias",
                    "content": "The  specified {User,Runas,Host,Cmnd}Alias was defined but never used.  The message is\nprefixed with the path name of the sudoers file and the line number  where  the  unused\nalias was defined.  You may wish to comment out or remove the unused alias.\n"
                },
                {
                    "name": "Warning: cycle in {User,Runas,Host,Cmnd}_Alias",
                    "content": "The  specified  {User,Runas,Host,Cmnd}Alias includes a reference to itself, either di‐\nrectly or through an alias it includes.  The message is prefixed with the path name  of\nthe  sudoers  file  and  the  line number where the cycle was detected.  This is only a\nwarning unless visudo is run in -s (strict) mode as sudo will ignore cycles when  pars‐\ning the sudoers file.\n"
                },
                {
                    "name": "ignoring editor backup file",
                    "content": "While  processing  a @includedir or #includedir, a file was found with a name that ends\nin ‘~’ or .bak.  Such files are skipped by sudo and visudo.\n"
                },
                {
                    "name": "ignoring file name containing '.'",
                    "content": "While processing a @includedir or #includedir, a file was found with a name  that  con‐\ntains a ‘.’ character.  Such files are skipped by sudo and visudo.\n"
                },
                {
                    "name": "unknown defaults entry \"name\"",
                    "content": "The sudoers file contains a Defaults setting not recognized by visudo.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "vi(1), sudo.conf(5), sudoers(5), sudo(8), vipw(8)\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Many people have worked on sudo over the years; this version consists of code written primar‐\nily by:\n\nTodd C. Miller\n\nSee  the  CONTRIBUTORS.md  file in the sudo distribution (https://www.sudo.ws/about/contribu‐\ntors/) for an 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 the editor used by visudo\nallows shell escapes.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "If  you  believe  you  have  found  a  bug  in  visudo,  you  can  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": "visudo is provided “AS IS” and any express or implied warranties, including, but not  limited\nto,  the  implied warranties of merchantability and fitness for a particular purpose are dis‐\nclaimed.  See the LICENSE.md file distributed with sudo or https://www.sudo.ws/about/license/\nfor complete details.\n\nSudo 1.9.15p5                               July 27, 2023                                  VISUDO(8)",
            "subsections": []
        }
    },
    "summary": "visudo — edit the sudoers file",
    "flags": [
        {
            "flag": "-c",
            "long": "--check",
            "arg": null,
            "description": "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 speci‐ fied, 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."
        },
        {
            "flag": "-f",
            "long": "--file",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "Display a short help message to the standard output and exit."
        },
        {
            "flag": "-I",
            "long": "--no-includes",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-O",
            "long": "--owner",
            "arg": null,
            "description": "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 er‐ ror will be reported if the owner is incorrect. This option is enabled by default if the sudoers file was not specified."
        },
        {
            "flag": "-P",
            "long": "--perms",
            "arg": null,
            "description": "Enforce the default permissions (mode) of the sudoers file. In edit mode, the per‐ missions 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."
        },
        {
            "flag": "-q",
            "long": "--quiet",
            "arg": null,
            "description": "Enable quiet mode. In this mode details about syntax errors are not printed. This option is only useful when combined with the -c option."
        },
        {
            "flag": "-s",
            "long": "--strict",
            "arg": null,
            "description": "Enable strict checking of the sudoers file. If an alias is referenced but not actu‐ ally 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."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "Print the visudo and sudoers grammar versions and exit. 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 pol‐ icy is evaluated in its entirety, it is not sufficient to check an individual sudoers include file for syntax errors."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "vi",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/vi/1/json"
        },
        {
            "name": "sudo.conf",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/sudo.conf/5/json"
        },
        {
            "name": "sudoers",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/sudoers/5/json"
        },
        {
            "name": "sudo",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/sudo/8/json"
        },
        {
            "name": "vipw",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/vipw/8/json"
        }
    ]
}