brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: visudo -c checks your sudoers files for syntax errors

Linux
~/tips/tip-security-visudo-check-sudoers

sudo visudo -c && echo sudoers ok

Checks sudoers and its included files for syntax errors and returns an exit code.

A typo in a sudoers file can lock you out of sudo. I never edit those files in a plain editor, and visudo can also check them without opening anything.

The -c option is check-only mode. It looks at the sudoers file and every file it includes for syntax errors, and it exits with 0 when all is well and 1 when it found a problem. That makes it easy to use in a script:

sudo visudo -c && echo sudoers ok

If you give no path, it also checks the owner and permissions of the file. To test one file before it goes live, add -f:

sudo visudo -c -f /etc/sudoers.d/myapp

I run this after every change to a drop-in in /etc/sudoers.d. Add -s for strict checking, which treats an undefined alias or a cycle in an alias as a syntax error.

A broken file is read on every sudo call, and once sudo fails you need another way to become root. Keep a root shell open in a second terminal, or make sure you have console access, until the check passes.

The check covers syntax only. A valid line can still give a user more rights than you meant, so read the rule once more after it passes.

Further reading: visudo(8) man page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link