Sudoers Rule Match Practice: Which Line Wins?
Unlimited sudoers practice. Each problem shows a user, the sudoers file, the files in /etc/sudoers.d and one sudo command: decide what happens, then tap the line that decides it. A wrong answer names the slip, such as expecting the most specific line to win.
The user
The files, oldest first
Which line decides it?
Users, groups and files are invented. Every line uses ALL for the host, there are no Defaults lines, aliases or ! negation, and sudo has no cached password. The sudoers.d files are shown in the order they were created, not the order sudo reads them.
For file modes and ownership, try the Linux file permission practice.
Linux exam prep
Configuring sudo is part of OS hardening on the CompTIA Linux+ XK0-006 exam. Start with the free real exam questions, then get the full pack.
Sudoers FAQ
Which sudoers line wins when several lines match?
The last one. The sudoers manual says that when multiple entries match for a user they are applied in order, and the last match is used, which is not necessarily the most specific match. A line that names the exact command does not beat a later line with ALL.
In what order does sudo read the files in /etc/sudoers.d?
In sorted lexical order, not in the order the files were made. The manual gives the example that 01_first is read before 10_second, and that 1_whoops would be loaded after 10_second because the sorting is not numeric. The same rule puts 10_web before 9_ops.
Why is my file in /etc/sudoers.d ignored?
sudo skips file names that end in ~ or contain a dot, to avoid package manager and editor temporary or backup files. A file called ops.conf or web.bak is never read, so its lines never match.
Where does @includedir put the sudoers.d rules?
At the place of the directive. sudo stops reading the current file, reads each file in the directory, and then returns to the file that held @includedir. A line in sudoers after the directive is read after every sudoers.d file, so it can be the last match.
Why does sudo still ask for a password when I set NOPASSWD?
Usually because another line that matches is read later and has no NOPASSWD: the last match decides, and its tags are the ones used. NOPASSWD sets a default only for the commands that follow it in the same entry, and PASSWD reverses it.
Does %group in sudoers match supplementary groups?
Yes. sudoers looks up each group the user is a member of, so a %wheel line matches a user who is in wheel as one of their other groups. In this drill those groups are listed under Also in.
What does (ALL:ALL) mean in a sudoers line?
It is the Runas_Spec, the as_whom part of "who where = (as_whom) what". The first list says which users the command may run as with sudo -u, and the second which groups with -g. With no Runas_Spec the command may run only as root, the default target user.
How do command arguments work in sudoers?
A command with no arguments in sudoers may be run with any arguments. When the line gives arguments, the arguments on the command line must match them. "" after a command allows it with no arguments only. ALL matches every command.
Does sudo remember my password?
For a short time. After you authenticate, sudo can be used without a password for 5 minutes unless timestamp_timeout says otherwise. The drill assumes no password is cached, so "Runs after a password" means sudo asks for it.
Which exam covers sudo?
The CompTIA Linux+ XK0-006 exam page lists OS hardening as "Apply permissions, configure sudo, and secure remote access."
What does this drill leave out?
Negation with !, aliases, Defaults lines, host names (every line uses ALL), wildcards and regular expressions, sudo -g, cached passwords, and files with a wrong owner or mode. File names are chosen so that sorting is the same in every locale. A rule with two commands is split over two rows with a backslash, which sudoers allows.
Sources
- sudo project, sudoers(5) manual: the last match is used; @includedir reads the files in sorted lexical order, skips names that end in ~ or contain a dot, and then returns to the file; user lists, %group and ALL; the Runas_Spec and the default of root; NOPASSWD and PASSWD set a default for the commands that follow; command arguments and ""; continued lines; the 5 minute password cache.
- sudo project, sudo(8) manual: -u runs the command as a user other than the default target user (usually root).
- CompTIA, Linux+ certification page: OS hardening, "Apply permissions, configure sudo, and secure remote access."
- Checked 22 November 2026. The tool's own approach: users, groups and files are invented; the cases listed under "What does this drill leave out?" never appear; "The checks" puts the documented steps into five lines; the sudoers.d files are shown in the order they were created. An independent re-solver (it parses the shown files again and scans the matches from the end) agreed with the drill on 20,000 generated problems.
Checked 22 November 2026 against the sudoers and sudo manuals at sudo.ws and the CompTIA Linux+ exam page.
- DrillLinux file permission practiceDecide if a user can read, write, run, delete or create from two ls -l lines.
- BuilderCron expression builderBuild a 5-field crontab schedule, read it in plain English and see the next 5 run times.
- Calculatorchmod calculatorLinux file permissions as numbers, letters and the exact chmod command, including SUID, SGID and the sticky bit.