Linux chfn command

Linux Commands List

chfn(Change Finger Information) is a command-line tool in Linux used to modify a user's personal description information.

chfnThe command is used to modify the user's finger information in the system, including full name, office address, office phone, home phone, etc.

This information can befingerviewed by other users using the command, making it convenient to know each other's contact information in a multi-user collaborative server environment.

In early Unix systems,fingerthe command could view detailed user information,chfnand provides an entry point to modify this information.

Althoughfingerthe frequency of use in modern systems has decreased, butchfnthe GECOS field managed by it is still used by many programs as the source of the user's display name.

The GECOS field is/etc/passwdthe 5th colon-separated field in the file, storing the user's description information.chfnEssentially, it is modifying this field.

Command syntax

chfnThe basic syntax is as follows:

chfn [选项] [用户名]

If no username is specified, the information of the currently logged-in user is modified by default.

Ordinary users can only modify their own information, while the root user can modify any user's information.


Options description

chfnThe common options are listed as follows:

OptionDescriptionExample
-f, --full-nameSet the user's full namechfn -f "Zhang San"
-r, --roomSet the office room numberchfn -r "A-301"
-w, --work-phoneSet the work phone numberchfn -w "010-12345678"
-h, --home-phoneSet the home phone numberchfn -h "010-87654321"
-o, --otherSet other information (Other, the rest of the GECOS field)chfn -o "Developer"
-u, --helpDisplay help informationchfn -u

Detailed usage

Modify personal information interactively

Run without any optionschfnwill prompt the user to input item by item interactively:

# 交互式修改当前用户信息
$ chfn
Password:
Changing the user information for example
Enter the new value, or press ENTER for the default
        Full Name: example
        Room Number []: A-301
        Work Phone []: 010-12345678
        Home Phone []: 010-87654321

Each prompt line displays the current value. If you don't want to modify a certain item, just press Enter to skip it.

The system will first require password verification to ensure that only the user themselves or root can modify.

Modify directly using options

In scripts or batch operations, you can use options to skip interactive prompts and directly specify new values:

# 一次性设置用户全名和办公室号码
$ chfn -f "Li Si" -r "B-202" example

After execution, the userexample's full name will be set to "Li Si", and office number to "B-202".

View the modified information

After the modification is complete, you can usefingercommand to view the updated information:

# 使用 finger 查看用户信息
$ finger example
Login: example                    Name: Li Si
Directory: /home/example          Shell: /bin/bash
Office: B-202, 010-12345678      Home Phone: 010-87654321
Last login Tue May 19 10:30 (CST) on pts/0
No mail.
No Plan.

If the system does not havefingerinstalled, you can usegetent passwd exampleto directly view/etc/passwdthe GECOS field in

Verify by directly reading /etc/passwd

The parts in the GECOS field are separated by commas, with the format:Full name, Office, Work phone, Home phone, Other。

# 查看 /etc/passwd 中 example 用户的 GECOS 字段
$ grep example /etc/passwd
example:x:1001:1001:Li Si,B-202,010-12345678,010-87654321:/home/example:/bin/bash

It can be seen that the GECOS field (the 5th colon-separated content) completely records all the information just set.

Modify a single item

You can modify only one item while keeping other information unchanged:

# 只修改全名,其他信息保持不变
$ chfn -f "Wang Wu" example

# 验证修改结果
$ finger example | grep Name
Login: example                    Name: Wang Wu

chfn configuration file

chfnThe behavior is controlled by/etc/login.defsthe configuration in:

Configuration itemDescriptionDefault value
CHFN_RESTRICTRestricts the fields that can be modified, using a combination of letters:f(full name),r(room),w(work phone),h(home phone)frwh

If set to an empty string, no user is allowed to modify finger information.

System administrators can control which fields users can modify by adjusting this configuration.


Notes

Ordinary users can only modify their own finger information and need to provide their current password for verification. The root user can modify any user's information without password verification.

chfnThe modified information will be written to/etc/passwdIncorrect modifications may cause some programs that depend on the GECOS field to display abnormally. It is recommended to back up the relevant lines before modifying.

If the system disableschfnthe function (CHFN_RESTRICTis empty), running this command will prompt insufficient permissions.

Some modern Linux distributions (such as Ubuntu) do not installfingerpackage by default; you need to manually runapt install fingerto install.

In centralized authentication environments such as LDAP or NIS,chfnmay not work properly; in such environments, the corresponding management tools should be used.


Related commands

CommandDescription
fingerView a user's finger information
chshModify a user's default login shell
chageModify user password expiration information
usermodModify various attributes of a user account (including the GECOS field)
passwdModify a user's password
getentRetrieve entry information from system databases

Linux Commands List

Other extensions