I know, in RHEL 7.8, that you can have blank lines in /etc/passwd

But can you have comment lines, and if so what would the line start with?


3 Answers 3


The musl C library routines for processing the account database, getpwent() et al., do not permit any sort of commentary in the /etc/passwd or /etc/shadow files. The library code simply does not treat any character as a comment introducer. (It also does not recognize a + line as a YP flag or permit any special markers at all.)

If you have any programs built against the musl C library, do not attempt adding comments to these files.

The GNU C library and FreeBSD C library, however, both do permit commentary.

Or, rather:

The GNU C library code providing the files sources of all NSS databases (see the nsswitch.conf manual) permits line comments with a # as the first non-whitespace character. So more than just /etc/passwd and /etc/shadow can contain comments.

On the BSDs, the /etc/passwd file is not the account database. On the BSDs the account database is not a flat file database, but is a Berkeley DB file (two, in fact, /etc/pwd.db and /etc/spwd.db), which by the nature of Berkeley DB files does not permit commentary. /etc/master.passwd is compiled into the account database(s) by the pwd_mkdb tool.

The /etc/passwd file on the BSDs is a dummy backwards-compatibility file emitted by pwd_mkdb, not actually used for lookups by C library routines and there only for people with shell scripts using direct awk /etc/passwd and the like, rather than the better getent passwd command (which wraps the C library for shell scripts).

On FreeBSD and its derivatives, /etc/master.passwd can contain comments and the pwd_mkdb tool copies commentary through from /etc/master.passwd to /etc/passwd, without putting it into the main Berkeley DB files. The # can optionally be preceded by exactly only TAB and SPC characters, which is not quite the same as the GNU C library (which allows any whitespace character that satisfies isspace() in the locale of the process using the GNU C library routines, which is probably a very obscure it-is-sometimes-a-comment-sometimes-a-secret-superuser-record bug waiting to happen).

OpenBSD's and NetBSD's pwd_mkdb commands, in contrast, do not allow for commentary in /etc/master.passwd and do not insert comments into the dummy /etc/passwd.

So you can use # comments preceded by TAB and SPC in /etc/master.passwd on FreeBSD; and # comments precended by the current locale's isspace() characters in /etc/passwd, /etc/shadow, and a whole bunch of other NSS sources on Linux-based operating systems as long as all (relevant) programs are linked against the GNU C library.


Only user entries are allowed in /etc/passwd, anything else is considered malformed and causes some tools that depend on this file to fail.



Each record in /etc/passwd describes one user account and comment lines are not supported.

See passwd(5) (man 5 passwd) for the file format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.