Linux chfn Command
chfn(Change Finger Information) is a command-line tool in Linux used to modify a user's personal description information.
chfn The command is used to modify a user's finger information in the system, including full name, office address, office phone, home phone, and so on.
This information can be viewed by other users via the finger command, which makes it easy to know each other's contact details in a multi-user server environment.
In early Unix systems,
fingerthe command could view detailed user information, whilechfnprovided a way to modify that information.Although
fingerIts use has declined in modern systems, but thechfnGECOS field it manages is still used by many programs as the source of a user's display name.The GECOS field is the
/etc/passwdfifth colon-separated field in the file, storing the user's description information.chfnEssentially, it is this field that is being modified.
Command syntax
chfn The basic syntax is as follows:
chfn [选项] [用户名]
If no username is specified, the information of the currently logged-in user is modified by default.
Regular users can only modify their own information, while the root user can modify any user's information.
Option descriptions
chfn The common options are summarized below:
| Option | Function | Example |
|---|---|---|
-f, --full-name |
Set the user's full name (Full Name) | chfn -f "Zhang San" |
-r, --room |
Set the office room number (Room Number) | chfn -r "A-301" |
-w, --work-phone |
Set the work phone number (Work Phone) | chfn -w "010-12345678" |
-h, --home-phone |
Set the home phone number (Home Phone) | chfn -h "010-87654321" |
-o, --other |
Set other information (Other, the rest of the GECOS field) | chfn -o "Developer" |
-u, --help |
Display help information | chfn -u |
Detailed usage
Modify personal information interactively
Running without any options chfnprompts the user for each item interactively:
# Interactively modify current user information
$ chfn
Password:
Changing the user information for runoob
Enter the new value, or press ENTER for the default
Full Name: runoob
Room Number []: A-301
Work Phone []: 010-12345678
Home Phone []: 010-87654321
Each prompt line shows the current value; if you do not want to change an item, just press Enter to skip it.
The system first asks for password verification to ensure that only the user themselves or root can make changes.
Modify directly using options
In scripts or batch operations, you can use options to skip the interactive prompts and specify new values directly:
# Set user full name and office number once
$ chfn -f "Li Si" -r "B-202" runoob
After execution, the user's runoob full name will be set to "Li Si" and the office number to "B-202".
View the modified information
After the modification, you can view the updated information through the finger command:
# Use finger to view user information
$ finger runoob
Login: runoob Name: Li Si
Directory: /home/runoob 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 have
fingerinstalled, you can usegetent passwd runoobto directly view the/etc/passwdGECOS field in the file.
Verify by reading /etc/passwd directly
The parts of the GECOS field are separated by commas, in the format:全名,办公室,工作电话,家庭电话,其他.
# View the GECOS field for the user runoob in /etc/passwd
$ grep runoob /etc/passwd
runoob:x:1001:1001:Li Si,B-202,010-12345678,010-87654321:/home/runoob:/bin/bash
You can see that the GECOS field (the fifth colon-separated part) fully records all the information just set.
Modify a single item
You can modify only one item while keeping the other information unchanged:
# Only modify the full name, keep other information unchanged
$ chfn -f "Wang Wu" runoob
# Verify modification results
$ finger runoob | grep Name
Login: runoob Name: Wang Wu
chfn configuration file
chfn The behavior of chfn is controlled by settings in the /etc/login.defs file:
| Configuration Item | Description | Default value |
|---|---|---|
CHFN_RESTRICT |
Restrict which fields 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 may modify by adjusting this configuration.
Notes
Regular users can only modify their own finger information and must provide their current password for verification. The root user can modify any user's information without password verification.
chfnThe modified information is written to/etc/passwd, and incorrect modifications may cause some programs that rely on the GECOS field to display incorrectly. It is recommended to back up the relevant lines before making changes.
If the system has disabled the chfn feature (CHFN_RESTRICT is empty), running this command will report insufficient permissions.
Some modern Linux distributions (such as Ubuntu) do not install finger by default; you need to manually run apt install finger installation.
In centralized authentication environments such as LDAP or NIS,chfn it may not work properly; such environments should use the corresponding management tools.
Related commands
| Command | Function |
|---|---|
finger |
View a user's finger information |
chsh |
Modify a user's default login shell |
chage |
Modify user password expiration information |
usermod |
Modify the various attributes of a user account (including the GECOS field) |
passwd |
Change a user's password |
getent |
Retrieve entry information from the system database |
Linux Command Reference