Just being curious about the following situation
When the adduser
command is executed as follows:
sudo adduser optimusprime
Adding user `optimusprime' ...
Adding new group `optimusprime' (1015) ...
Adding new user `optimusprime' (1013) with group `optimusprime' ...
Creating home directory `/home/optimusprime' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for optimusprime
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
Observe there are 5 optional fields available to write data. If they are left empty as default when the cat /etc/passwd
command is executed, the record for that user appears as follows:
optimusprime:x:1013:1015:,,,:/home/optimusprime:/bin/bash
Observe the ,,,
GECOS part. It represents 4 fields as A,B,C,D
and not 5 as A,B,C,D,E
. Why this difference or mismatch between them? To be honest I expected
optimusprime:x:1013:1015:,,,,:/home/optimusprime:/bin/bash
Which represents the 5 fields available through the adduser
command too.
And if is used the usermod
command as follows:
sudo usermod -c "A,B,C,D,E" optimusprime
The user appears as:
optimusprime:x:1013:1015:A,B,C,D,E:/home/optimusprime:/bin/bash
I know is possible even add more fields through the usermod
command as follows:
sudo usermod -c "A,B,C,D,E,F" optimusprime
sudo usermod -c "A,B,C,D,E,F,G" optimusprime
Therefore these commands executions are reflected as follows respectively
optimusprime:x:1013:1015:A,B,C,D,E,F:/home/optimusprime:/bin/bash
optimusprime:x:1013:1015:A,B,C,D,E,F,G:/home/optimusprime:/bin/bash
At a first glance is not clear if GECOS as minimum is based on 4 or 5 fields.
The manual page for the /etc/passwd file,
man 5 passwd
, is particularly terse in this regard:POSIX isn't any help either - in fact, the POSIX standard for the password structure, pwd.h, doesn't mandate a GECOS or comment field at all:
If we look at the glibc implementation i.e.
/usr/include/pwd.h
as provided by thelibc-dev
package, we see that itspw_gecos
member is a simple C string (or pointer-to-char):so any application that obtains password database information using the glibc
getpwent
family of functions will obtain the result as single string - it is essentially up to the application how it chooses to parse it. In particular, the BSD implementation of thefinger
command - which is what you get if you installfinger
from the Ubuntu universe repository - tokenizes the string using strsep but only assigns at most four comma-separated subfields:In Ubuntu,
/usr/sbin/adduser
is a perl script that uses the system'schfn
. If you look at the source forchfn
(from the shadow passwd suite) it tokenizes the first four subfields similarly then assigns the rest as "slop
":So I guess the conclusion is
there's no standard for the GECOS field
the first 4 subfields have conventional interpretations based on the historical
finger
commandanything after that is optional and subject to application-dependent interpretation.