
chfn Command in Linux
The chfn command in Linux allows you to modify a user's finger information, which is stored in the /etc/passwd file. This information is typically viewed using the finger command and includes details like the user's real name, work details (room and phone number), and home phone number.
The chfn command is particularly useful in environments where user information needs to be accurate and up-to-date, such as in a corporate setting where contact details are necessary for communication. It's also beneficial for system administrators who manage multiple users and need to ensure that user information is kept current.
Table of Contents
Here is a comprehensive guide to the options available with the chfn command −
- Understanding chfn Command in Linux
- Install chfn Command in Linux
- How to use chfn Command in Linux?
- Examples of chfn Command in Linux
- Alternatives of chfn Command in Linux
Understanding chfn Command in Linux
Linux, the powerhouse of operating systems used by developers and system administrators worldwide, offers a plethora of commands for various tasks. One such command is chfn, which stands for 'change finger information'.
This command is a vital tool for managing user information on a Linux system. The chfn command allows users to change or view their own user information stored in the /etc/passwdfile.
The /etc/passwd file contains user account information, which is not only crucial for system administration but also for user identification.
Install chfn Command in Linux
The chfn command is likely already installed on your Linux system by default. It's a common utility included in most major distributions. Here's how to check if it's available −
Try running chfn without any arguments. If it's installed, you should see the interactive mode prompting you to edit your finger information. Alternatively, use the command or type command to check if chfn is available −
command -v chfn or type chfn

These commands display the location of the chfn executable if it's found in your system's PATH environment variable.
In the rare case that chfn is not installed −
Some distributions might not include chfn by default. Here's how to install it depending on your package manager −
Debian/Ubuntu-based systems −
sudo apt update sudo apt install shadow # chfn is usually part of the shadow package
Red Hat/CentOS-based systems −
sudo yum update sudo yum install shadow-utils # chfn is included in shadow-utils
Once you've run the appropriate update and installation command, you should have chfn available on your system. You can verify its presence using the methods mentioned earlier.
How to use chfn Command in Linux?
The chfn command is straightforward to use, with a syntax that allows for quick modifications to a user's information. The chfn command provides a simple way to update details like the user's full name, office room number, work phone number, and home phone number. This information can be displayed using the finger command, which is a user information lookup program.
The basic syntax of the command is as follows −
chfn [options] [LOGIN]
Here's a breakdown of the different options available with chfn. The options available with chfn are −
Options | Descriptions |
---|---|
-f or --full-name | This option allows you to change the full name associated with the user account. |
-r or --room | With this option, you can update the office room number for the user. |
-w or --work-phone | This option is used to change the work phone number. |
-h or --home-phone | Use this to update the home phone number in the system. |
-o or --other | This is a versatile option that lets you change other details associated with the user account. |
Examples of chfn Command in Linux
Let's delve into some practical examples of how the chfn command can be utilized −
Example 1: Changing the Full Name
To change a user's full name, the -f option is used followed by the new full name and the username. For example, to change a user's full name, one would use sudo chfn -f "New Name" username −
sudo chfn -f "Linux_user" linux

Example 2: Updating the Work Phone Number
The -w option allows the modification of the user's work phone number. It attempts to change the work phone number of the user in the current linux environment using administrative privileges −
sudo chfn -w "123-456-7890" linux

Example 3: Modifying the Room Number
With the -r option, users can change their office room number. It instructs Linux to set the user's workroom number to "101A" with root privileges −
sudo chfn -r "101A" linux

Example 4: Changing the Home Phone Number
The -h option is designated for updating the home phone number. The command uses root privileges (sudo) to update the user's home phone number to "098-765-4321" on a Linux system −
sudo chfn -h "098-765-4321" linux

Example 5: Adding Other Information
The -o option is used for adding any other additional information. The command attempts to set the user's "other" information field in the finger entry to "Additional Info" on a Linux system, requiring root access (sudo) −
sudo chfn -o "Additional Info" linux

Example 6: Verifying Changes
After making changes, it's important to verify that the information has been updated correctly. This can be done using the finger command −
finger linux

Example 7: Interactive Mode (Default)
If you run chfn without any arguments, it enters an interactive mode. Here, the system will display your current finger information and prompt you to change each field individually −
chfn

You can enter the new information or simply press Enter to leave the field unchanged.
Manual Configuration
The finger information fields modified by chfn are collectively referred to as the gecos field. By default, chfn allows edits to the full name, work details (room and phone), and home phone. However, some systems might restrict editable fields through the configuration file /etc/login.defs. This file defines a variable named CHFN_RESTRICT which can specify limitations −

- CHFN_RESTRICT=yes − This restricts changes to work details (room and phone) and home phone only.
- CHFN_RESTRICT=no − This allows editing of the full name along with work and home phone details.
Note − It's important to note that while a normal user can change their own information, only the superuser (root) can modify the information for any account. Additionally, certain fields have restrictions on the characters they can contain such as avoiding colons, commas, equal signs, and non-US-ASCII characters, especially in phone numbers.
Alternatives of chfn Command in Linux
The chfn command itself doesn't have direct alternatives in Linux for modifying finger information. However, depending on what you want to achieve, here are some approaches you can consider −
1. Using usermod
The usermod command offers a more comprehensive way to manage user accounts, including some finger information. While it doesn't directly target the gecos field, you can modify specific details.
2. Manual Edit of /etc/passwd (Caution Advised)
This approach requires root access and should be done with caution as modifying system files directly can lead to errors.
The /etc/passwd file stores user account information, including the gecos field. An experienced user can edit this file to modify specific finger information entries. However, it's crucial to understand the file format and potential security risks before proceeding.
3. Third-Party Tools (Less Common)
Some system administration tools might offer functionalities similar to chfn. However, these are typically less common and depend on your specific distribution or environment.
Conclusion
The chfn (Change Finger) command in Linux is a utility that allows users to modify their user information stored in the /etc/passwdfile. This information, often used by the finger command, includes the user's real name, office room number, work phone number, and home phone number.
The chfn command is a simple yet powerful tool for managing user information on Linux systems. By understanding its syntax and options, users and administrators can efficiently update essential details, maintaining an organized and functional system environment.