OPINIONATED OMARCHY
TROUBLESHOOTING CORPUS
790
RECORDS
790
AUDITED
0
UNCHECKED
2388
SOURCES
LIVE
security medium occasional DISPUTE

A hand-edited /etc/sudoers locks you out of sudo: wrong owner or mode refuses everyone, a syntax error drops the broken line

omarchyarch
CORRECTED An auditor found the fix wrong or incomplete and rewrote it. · checked against Omarchy 4.0.2-1 on 2026-09-18
AUDIT NOTE

Checked against sudo 1.9.17p2 source at the pinned sha, which is the v1.9.17p2 tag and matches the installed 1.9.17.p2-6. Held: the owner and mode checks (lib/util/secure_path.c, messages in plugins/sudoers/sudoers.c) refuse before any rule is read, so a wrong owner or a world-writable file locks out everyone, and chmod 777 does not get sudo working, as danger says. Wrong: the record's claim that a syntax error leaves no valid source and prints 'no valid sudoers sources found, quitting'. plugins/sudoers/file.c returns the parse tree when parse_error is set and error recovery is on, sudoers(5) says error_recovery defaults to true since 1.9.3 and discards only the rest of the offending line, and that message is printed only when more than one sudoers source is configured. On this version a syntax error drops the broken line and the lockout is partial. Wrong: 'group- or world-writable' in danger. secure_path.c allows group write when the group is the sudoers gid (root here). Wrong on Omarchy: the recovery path hedges on whether a root password exists. The ISO configurator writes root_enc_password with the same hash as the user, the first-boot form says the password is used for user and root, and omarchy-provision-owner runs chpasswd for both, so su - is the primary recovery on a stock install. Missing: visudo's compiled-in fallback editor is /usr/bin/vi (in the binary, and the man page names --with-editor), Omarchy installs neovim only and no /usr/bin/vi exists here, and sudo strips EDITOR/VISUAL/SUDO_EDITOR except for the visudo env_keep line in the stock sudoers template, so visudo from su - or a chroot needs EDITOR=nvim or it stops with 'no editor found'. The ISO route was under-specified: the Omarchy ISO is seeded from archiso's releng profile (build-iso.sh), which ships arch-install-scripts and cryptsetup, autologs root on tty1 where the installer runs, and gives root an empty password, so a second console is the way to a shell. Stated from those sources, not tested. Severity lowered to medium under the brief's scale: the lockout exposes nothing, and the chmod 777 trap gives root only to code already running as a local account. Not exercised: no sudoers file, mode, su, visudo or chroot was run on this workstation. The title also overstates: merge_gapfill has no corrected_title, so the operator should retitle by hand to 'A hand-edited /etc/sudoers locks you out of sudo: wrong owner or mode refuses everyone, a syntax error drops the broken line'.

The cause above was rewritten on 2026-09-18 to match this note; the fix was corrected by the audit itself.
RISK

The panic fix to avoid is loosening the file instead of correcting it. chmod 777 /etc/sudoers, or a chmod -R run one directory too high, does not get sudo working: sudo checks the mode before reading a rule and refuses while the file is writable by anyone other than root (world-writable, or group-writable by a group other than root). It does hand root to anything on the machine that can now write the file, because the next line appended is one sudo will honour as soon as the mode is put back. Restore root:root and 0440, or let visudo do it on save.

The su - route works because Omarchy's installer gives root your account password. If you have since set a different root password, or locked the account, use the ISO route.

Symptom

After editing /etc/sudoers, or a file under /etc/sudoers.d/, with a plain editor instead of visudo, or after a chmod or chown touched it, sudo fails. With the wrong owner or mode it fails for every user, with a message such as /etc/sudoers is owned by uid 1000, should be 0 or /etc/sudoers is world writable, followed by sudo: unable to initialize policy plugin. With a syntax error it prints the file, line and column, for example /etc/sudoers:12:9: syntax error, and then either tells you that you are not in the sudoers file, if your grant was on the broken line, or keeps working while printing the error on every run.

Cause

sudo opens and parses /etc/sudoers on every invocation, for every user including root, with no cache. Before it reads a rule it checks the file (sudo 1.9.17p2, the version installed here, in lib/util/secure_path.c with the messages in plugins/sudoers/sudoers.c): it must be a regular file, owned by uid 0, not world-writable, and not group-writable unless its group is the compiled-in sudoers group, which is root here (ls -l /etc/sudoers shows -r--r----- 1 root root, the 0440 that sudoers(5) gives as the default mode). Any of those failing is logged as a parse error, the file is never opened, and with no other sudoers source configured sudo stops with unable to initialize policy plugin. That refusal is for everyone, because the check comes before any rule is read.

A syntax error behaves differently on this version. Since sudo 1.9.3 the error_recovery plugin option defaults to true, and sudoers(5) describes it as: "sudoers will try to recover from a syntax error by discarding the portion of the line that contains the error until the end of the line." sudo_file_parse() in plugins/sudoers/file.c returns the parsed policy when recovery is on, so the rules on the other lines still apply. Whether you are locked out depends on which line you broke: a typo in your own %wheel ALL=(ALL:ALL) ALL line drops that grant, a typo elsewhere leaves sudo working with the error printed every time. The older behaviour, where any syntax error refused everyone, is what most guides still describe.

visudo exists to prevent both failure modes. It locks the file, parses it before saving and refuses to save a syntax error, and unless you name an alternate file it applies -O and -P by default, restoring the default owner and mode on save. A plain editor, or a stray chmod or chown, bypasses all of that.

Fix

Edit /etc/sudoers and anything under /etc/sudoers.d/ with visudo only:


sudo visudo
sudo visudo -f /etc/sudoers.d/<file>

The stock sudoers template keeps SUDO_EDITOR, EDITOR and VISUAL for visudo (Defaults!/usr/bin/visudo env_keep += "SUDO_EDITOR EDITOR VISUAL"), so it opens in the editor Omarchy's shell exports.

If sudo is already broken, sudo visudo is broken the same way, and you need a root shell that does not go through sudo. On Omarchy that shell is one command away: the installer sets the root password to the same password as your account (root_enc_password in the ISO configurator, and omarchy-provision-owner runs chpasswd for both), so unless you changed it:


su -
EDITOR=nvim visudo

EDITOR=nvim matters. visudo's compiled-in fallback editor is /usr/bin/vi, which Omarchy does not install, and root's login shell exports no editor, so a bare visudo there stops with no editor found (editor path = /usr/bin/vi).

If the root password is not usable, boot the Omarchy ISO. It runs the installer on the first console, so switch to a second one with Ctrl+Alt+F2 and log in as root with an empty password, which the Arch releng profile the ISO is built on provides. Then unlock and mount the installed root and chroot into it:


cryptsetup open /dev/<your LUKS partition, from lsblk> root   # skip on an unencrypted install
mount -o subvol=@ /dev/mapper/root /mnt                       # the root partition itself if unencrypted
arch-chroot /mnt
EDITOR=nvim visudo

visudo reports the line and column of a syntax error, refuses to save until the file parses, and puts the owner and mode back to root:root and 0440 on save. If the damage is in a file under /etc/sudoers.d/, open that one with visudo -f. Then exit the chroot and reboot.

Verify

sudo -l lists your privileges with no error printed above them, sudo visudo -c reports /etc/sudoers: parsed OK and the same for each file under /etc/sudoers.d/, and ls -l /etc/sudoers shows -r--r----- 1 root root.

Sources

sudoers-syntax-error-or-mode-locks-out-sudo