050-720 · Question #358
The useradd command is used to create new users. Which file contains information on the primary group, shell, and other parameters to be used by useradd when not specified on the command line?
The correct answer is D. /etc/default/useradd. See the full explanation below for the reasoning.
Question
The useradd command is used to create new users. Which file contains information on the primary group, shell, and other parameters to be used by useradd when not specified on the command line?
Options
- A/etc/profile
- B/etc/passwd
- C/etc/shadow
- D/etc/default/useradd
How the community answered
(62 responses)- A3% (2)
- B15% (9)
- C8% (5)
- D74% (46)
Community Discussion
7The answer is D, /etc/default/useradd, and our group pretty much agreed on this one right away once we talked through the distractors. That file is specifically where useradd looks for its fallback values, things like the default shell, the default group, the home directory base path, and the skeleton directory, whenever you run the command without supplying those options explicitly. /etc/passwd stores the actual user records that already exist on the system, so it is a result of useradd running, not a config source for it. /etc/shadow is just for encrypted passwords and aging policies, and /etc/profile is a shell initialization script that runs at login, completely unrelated to how new accounts get created. A few people in our group were tripped up by /etc/passwd because it does contain shell and group info, but that is per-user data already written in, not the template useradd reads from. If you want to verify this on a Linux box, just run "cat /etc/default/useradd" and you will see those default values sitting right there. Anyone in the group want to add anything or push back on any of this?
One thing worth having a card for separately: useradd also reads /etc/login.defs for defaults like UID ranges, password aging, and whether to create a home directory, so that file and /etc/default/useradd work together rather than one being the whole story.
I almost picked B because /etc/passwd does store user info including shell and primary group, so my brain jumped to it as the "user defaults" file. But the question says "parameters to be used by useradd when not specified," which is specifically about the command's own default configuration, and that lives in /etc/default/useradd, not in passwd which just stores already-created user data.
Saw this exact question on my 050-720 and my brain went straight to /etc/passwd before I caught myself, because that file stores user account data but it does not store the defaults useradd falls back on when you leave options blank. Run "useradd -D" on any Linux box and it reads right from /etc/default/useradd, which is what locked D in for me before I even finished reading the other options.
Good catch on the self-correction, Ingrid, and worth adding that on systems using the useradd defaults from /etc/login.defs as well, the two files actually split the defaults between them, so knowing which setting lives where can save you on a trick question.
The shadow file trips people up here because it sounds like it stores "extra" user info beyond passwd, so I get why someone might second-guess D, but shadow is strictly for password hashing and aging fields. Run "useradd -D" on any Linux box and you'll see it's pulling straight from /etc/default/useradd, which is exactly what that file is for.
Yes, and worth noting that on systems using PAM, /etc/login.defs is also consulted for defaults like UID/GID ranges and password aging policies, so /etc/default/useradd is not the only config source for useradd behavior.