There’s more to a user account than a user name. Learn how to set and change all the metadata associated with a Linux user account from the command line.
What’s in a Name?
If you use a Linux or Unix-like computer, you’ll have a user account. The name given to the account is your user account name. This is the name you use to log in with. It’s also (by default) the name of your login group and the name of your home directory. They all use the same identifier.
There is another set of information that can be stored for each user account. Real-world data such as the person’s full name, their office number, and their work telephone number, for example, can be defined and attached to them. Indeed, completely arbitrary snippets of information can be tagged to user accounts.
In practical terms, this will be more useful for system administrators looking after computers that have many user accounts configured on them. But even for the single-user Linux computer, it’s always interesting to know what’s going on beneath the hood.
The GECOS Field
At one time, the pioneers of Unix had no printer of their own. They had to spool their print jobs to a General Electric mainframe that was running the General Electric Comprehensive Operating System (GECOS). To accomplish that, the users on the Unix systems needed to store and use the credentials of an account on the GECOS system.
The GECOS field was created to store those credentials. That very niche requirement has long since passed into history, and the GECOS field has been re-purposed to store other data related to the owner of the user account. It may have a new job, but it retains its old name. It is still called the GECOS field.
The field is stored in the
/etc/passwd file, along with other information regarding the user account:
- The account user name.
- The user ID.
- The group ID.
- The path to the home directory for the user account.
- The shell that is started when the user logs in.
This is where the finger command and the pinky command retrieve the information that they display.
RELATED: How to Use the finger Command on Linux
The chfn Command
chfn (change finger information) allows you to set and alter the information stored within the GECOS field. The information is stored as a comma-separated list within the field.
chfn command was already present on Ubuntu 18.04.1 and Manjaro 18.1.0. It had to be installed on Fedora 31. Use this command to install it:
sudo dnf install util-linux-user
Let’s see what
finger can find out about the owner of the user account “dave.” To get the maximum information, we’ll use the
-l (long format) option:
finger dave -l
This is what it could find:
It retrieves the account user name, the home directory, and the default shell. These are all related to the user account. They don’t refer to the real person who uses that account. We can use the
chfn command to store information about the actual person.
chfn in this way starts a short, interactive process. You are prompted to type in a data value for each piece of information that the GECOS field can hold. The current value for each data value is displayed in brackets . If you want to keep the current data, you can press the “Enter” key, and the value within the brackets will be retained.
The information we entered was:
- Room number: 512
- Work phone: 555-4567
- Home phone: 555-5432
Let’s check that
finger picks up that new information:
finger dave -l
Yes, it does. But you may have noticed that it didn’t prompt to change the full name. It’ll only do that if you use
sudo. But we don’t have to go through the whole
chfn session again, just because we forgot to use
sudo. We can change any of the data values individually.
Changing the Individual Data Values
We can set the full name for the owner of the user account by using the
-f (full name) option, together with
sudo chfn -f "Dave McKay" dave
And if we check once more with
We can see that the full name has been added.
There are other options to change the room number, home phone number, and work phone number. To change the room (office) number, use the
-r (room number) option:
sudo chfn -r 633 dave
Note that on some distributions, you might use the
-o (office room number) option instead of the
-r option. More on this shortly. For now, to see the options for your version of
To change the office telephone number, use the
-w (work telephone) option:
sudo chfn -w 555-1122 dave
And finally, to change the home telephone number use the
-h (home telephone number) option:
sudo chfn -h 555-6576 dave
finger again to see if all of those changes have been accepted:
finger dave -l
Success. All of those commands have worked, and the data values have been updated.
Using chfn On Other User Accounts
So much for changing our own information, what about changing the GECOS information for other users? That’s just as easy. You must use
sudo when you do, but that’s the only difference. Let’s check what data is set for user account mary:
finger mary -l
The usual default information is set for this user account. Let’s add to the information:
sudo chfn mary
We’ll run through the same session as we did before, being prompted for a data value for each piece of information that can be stored. And because we used
sudo , we are asked for the full name data value.
Wait a moment, what’s that last item, called “Other?”
it isn’t supported by all versions of
chfn, and you only see it if you use
sudo, which is why we didn’t see it earlier when we (deliberately) didn’t use
The “Other” data value can hold anything you like. It doesn’t have any prescribed or expected use.
chfn that support the “Other” field also provide the
-o (other) option to change this value directly. It’s because of the conflict between
-o for “office number” and
-o for “other” that some systems use
-r for “room number”.
We can see the data stored for user account mary in the
/etc/paswd file, by using
On systems that support it (check the
man page for your version of
chfn ) you can set the “other” field directly using the
-o (other) option:
sudo chfn -o "HTG Freelancer" dave
And we can check the data for user account dave using the
[asswd in a terminal window” width=”646″ height=”382″ />
That raises an obvious question. If your version of
chfn doesn’t support the “Other” field, how do you change it? We can do that with the
The usermod Command
usermod command allows you to modify aspects of a user account through such actions as adding or remove the user account from groups, and changing their default shell. It can also be used to directly manipulate the GECOS field.
Let’s take a closer look at the line in the
/etc/passwd file for user account mary. We’ll use grep to isolate that line for us. This will work because user names have to be unique. There can only be one user account called mary.
grep mary /etc/passwd
The fields in the
etc/passwd file are displayed. A colon “
:” is used as the field separator. from left to right, the fields are:
- The account user name.
- An “x” which indicates the password for this user account is held encrypted in the
- The user ID for the mary user account.
- The group ID for the mary user account.
- The GECOS field.
- The path to the home directory for the mary user account.
- The shell that is started when the owner of the mary account logs in.
A comma “,” is used as the separator for the data values within the GECOS field. The values within the GECOS field are, from left to right:
- Full Name.
- Room (or office) number.
- Work telephone number.
- Home telephone number.
- Other information.
Note that the
usermod command sets the entire GECOS field to the new value you provide. If all you provide is the full name of the person, then the only thing in the GECOS field will be the full name. This means you have to provide any existing data values that you wish to keep.
Here’s an example. The user Mary has been promoted, and she is going to move to the fourth floor. She’s getting a new office number, a new work telephone number, and we’re going to add in her middle name. Her “Other” field value is also going to change. Although her home telephone number is not going to change, we must provide it in the string to
We need to use the
-c (comment) option and we need to run the command with
sudo usermod -c "Mary Carol Quinn,405,5559654,555-7704,Linux Advocate" mary
grep to report on the contents of the
/etc/passwd file for mary, shows us the new values have been added.
grep mary /etc/passwd
RELATED: Add a User to a Group (or Second Group) on Linux
All is Flux, Nothing Abides
Inaccurate data is worthless. When the information about people changes—office moves, name changes, role titles—you can easily update their meta-data to reflect the current position.
- › How to Add Users on Linux
- › Everything You Ever Wanted to Know About inodes on Linux
- › How to List All Users In a Group on Linux
- › How to Add a User to the sudoers File in Linux
- › How to List Users in Linux
- › Systemd Will Change How Your Linux Home Directory Works
- › Before DVDs, There Were VCDs: The Video Disc Everyone Forgot
- › How to Turn On or Off the Always On Display for Android