know about GECOS in Linux

Question: What is GECOS in Linux ? How to set GECOS for user on Linux ?

Answer: GECOS in linux is also known as comment field for User.The comment or GECOS field is used for informational purpose.
In comments field generally we write the information related to user for eg. employee id,phone number,department name,branch name etc.

GECOS/Comments field are saved in /etc/passwd file in Linux system (Also applicable to Other Unix like operating system)

GECOS stands for “General Electric Comprehensive Operating System” . GECOS was renamed to GCOS when GE’s large systems division was sold to Honeywell.

GECOS/Comment field are saved in /etc/passwd file

The GECOS or comment field are saved in /etc/passwd file in Linux/Unix.
The fifth field in /etc/passwd file is for GECOS. (See below given screenshot)
To get the GECOS comment,use below given command

Syntax:

grep User-name /etc/passwd

Example:
GECOS

Advantage Of Using Gecos

(1) The User’s important information can be saved by using GECOS field (or comment field)

(2) In case, in a company have 2 person with same name.Both require login in system.It is obvious thier employee id will be different.We can mention employee id along with name in GECOS/comment section. (or any information you can write which help to identify the user)

Methods to set GECOS/Comment field to user on linux

(1) Set GECOS/Comment field at the time of creating user (By using useradd/adduser command)

(2) Set GECOS/Comment field after creating the user (By using usermod and chfn command)

(i): Useradd command to set GECOS for user in Linux
With useradd command use -c or --comment option to set GECOS/Comment for user.

Syntax:

useradd -c "Write the information" User-name

Example:

useradd -c "System Administrator,IT Department" sharad

(ii) Usermod command to set/modify the GECOS/Comment field for user in Linux
By using usermod command,you can also set or modify the GECOS field. In case,while creating the user you forgot to set GECOS for user.Then you can use usermod command.
Even you can also modify the GECOS field of user by using usermod command.

Use -c or --comment option with usermod command

Syntax:

usermod -c "Write the information" User-Name

Example:

usermod -c "Linux System Engineer, Ops Team" sharad

(iii) chfn command to modify GECOS/Comment field for user in Linux
chfn command changes the user’s account information like full name,room number, working phone number,home phone number etc. The information feeded with chfn command can be printed by using finger.

In below given syntax,select the options you want to feed for user’s account.

Syntax:

chfn [-f full_name] [-r room_no] [-w work_ph] [-h home_ph] [-o other] [user]

Example :

chfn -f "sharad chhetri" -r "111" -w "91-000000" -h "91-0000001" sharad

The output from finger command

The finger command shows the information which is set in GECOS/Comment field by using chfn command

root@tuxworld:~# finger -m sharad
Login: sharad         			Name: sharad chhetri
Directory: /home/sharad             	Shell: /bin/bash
Office: 111, 91-000000			Home Phone: 91-0000001
Last login Fri Jan  3 21:38 (IST) on tty3
No mail.
No Plan.
root@tuxworld:~#

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.