Is it possible to perform a visudo sanity check for a file in the context of other files included from /etc/sudoers.d?


I want to add a new file to /etc/sudoers.d the file itself is correct and it passes the visudo -c parser.

It does however contain a Cmnd_Alias line which conflicts with another file in etc/sudoers.d.

If moved to a /etc/sudoers.d it would break the sudo command with Alias '<name>' already defined near line error.


Is there any method which I could employ to check if the new file wouldn't break the sudo after placing it in sudoers.d?

Or is there any method to make sudo ignore/stop processing included files if there was any error encountered?

1 Answer 1


You might try checking a concatenation of /etc/sudoers and the proposed new file:

sudo bash -c 'visudo -cf <(cat /etc/sudoers /path/to/to-be-added-file)'

Since visudo will parse the #includedir in /etc/sudoers, all the relevant files in sudoers.d would be checked as well.

$ sudo cat /etc/sudoers.d/foo
Cmnd_Alias FOO = /bin/bar
$ sudo cat /tmp/bar
Cmnd_Alias FOO = /bin/foo
$ sudo bash -c 'visudo -cf <(cat /etc/sudoers /tmp/bar)'
>>> /dev/fd/63: Alias `FOO' already defined near line 31 <<<
parse error in /dev/fd/63 near line 31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .