YouTip LogoYouTip

Linux Comm Chfn

[![Image 1: Linux Command Manual](#) Linux Command Manual](#) `chfn` (Change Finger Information) is a command-line tool in Linux used to modify a user's personal description information. The `chfn` command is used to modify a user's finger information in the system, including full name, office address, office phone, and home phone. This information can be viewed by other users via the `finger` command, making it convenient to understand each other's contact details in a multi-user collaborative server environment. > In early Unix systems, the `finger` command could view detailed user information, and `chfn` provided the entry point to modify this information. > > > Although `finger` is used less frequently in modern systems, the GECOS field managed by `chfn` is still used by many programs as the source for a user's display name. > > > The GECOS field is the 5th colon-separated field in the `/etc/passwd` file, storing the user's description information. `chfn` essentially modifies this field. ### Command Syntax The basic syntax for `chfn` is as follows: chfn If no username is specified, it defaults to modifying the information of the currently logged-in user. A regular user can only modify their own information, while the root user can modify any user's information. * * * ## Option Description The common options for `chfn` 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 ### Interactively Modify Personal Information Running `chfn` without any options will prompt the user to enter information interactively, item by item: # Interactively modify current user information $ chfn Password:Changing the user information for tutorial Enter the new value, or press ENTER for the default Full Name: tutorial Room Number []: A-301 Work Phone []: 010-12345678 Home Phone []: 010-87654321 Each prompt line displays the current value. If you do not wish to modify an item, simply press Enter to skip it. The system will first require password verification to ensure that only the user themselves or root can make changes. ### Use Options to Modify Directly In scripts or batch operations, you can use options to skip interactive prompts and directly specify new values: # Set user full name and office number in one go $ chfn -f "Li Si" -r "B-202" tutorial After execution, the full name of user `tutorial` will be set to "Li Si", and the office number to "B-202". ### View Modified Information After modification, you can view the updated information using the `finger` command: # Use finger to view user information $ finger tutorial Login: tutorial Name: Li SiDirectory: /home/tutorial Shell: /bin/bash Office: B-202, 010-12345678 Home Phone: 010-87654321Last login Tue May 19 10:30 (CST) on pts/0No mail.No Plan. > If `finger` is not installed on the system, you can use `getent passwd tutorial` to directly view the GECOS field in `/etc/passwd`. ### Directly Read /etc/passwd to Verify The parts in the GECOS field are separated by commas, in the format: `full name, office, work phone, home phone, other`. # View the GECOS field for user tutorial in /etc/passwd $ grep tutorial /etc/passwd tutorial:x:1001:1001:Li Si,B-202,010-12345678,010-87654321:/home/tutorial:/bin/bash You can see that the GECOS field (the 5th colon-separated content) completely records all the information just set. ### Modify a Single Item You can modify just one item while keeping other information unchanged: # Only modify the full name, keep other information unchanged $ chfn -f "Wang Wu" tutorial # Verify the modification result $ finger tutorial | grep NameLogin: tutorial Name: Wang Wu * * * ## chfn Configuration File The behavior of `chfn` is controlled by the configuration in `/etc/login.defs`: | Configuration Item | Description | Default Value | | --- | --- | --- | | `CHFN_RESTRICT` | Restricts 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 adjust this configuration to control which fields users are allowed to modify. * * * ## Notes > A regular user can only modify their own finger information and must provide the current password for verification. The root user can modify any user's information without password verification. > The information modified by `chfn` is written to `/etc/passwd`. Incorrect modifications may cause display anomalies in some programs that depend on the GECOS field. It is recommended to back up the relevant line before modification. If the system has disabled the `chfn` functionality (`CHFN_RESTRICT` is empty), running the command will prompt for insufficient permissions. Some modern Linux distributions (e.g., Ubuntu) do not install the `finger` package by default; you need to manually run `apt install finger` to install it. In centralized authentication environments like LDAP or NIS, `chfn` 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 various attributes of a user account (including the GECOS field) | | `passwd` | Modify a user's password | | `getent` | Retrieve entry information from system databases | [![Image 2: Linux Command Manual](#) Linux Command Manual](#)
← Linux Comm UseraddLinux Comm Adduser β†’