What is /etc/passwd file in Linux?

Filed Under: UNIX/Linux
etc/passwd file in linux

/etc/passwd in Linux is a file that stores the list of users on the system along with important information regarding these users. Identifying users uniquely is essential and necessary at the time of login. /etc/passwd is used by Linux system at the time of login. The file should be readable by all users but write permission should only belong to the root user.

Understanding the /etc/passwd file

To view the contents of the file use cat command.

$ cat /etc/passwd
Etc/passwd File

The output will look something like this. Here each line represents a user. Each user has a list of parameters separated by ‘:’

The seven fields are :

  • Login name
  • Encrypted Password
  • UID number
  • GID number
  • GECOS
  • Home directory
  • Login shell

Let’s see what each of them mean :

  1. Login name: The unique name given to a user. It is case sensitive.
  2. Encrypted Password: This field is for the encrypted password. However, in most modern Linux systems, the password is stored in a shadow file named /etc/shadow. The ‘x’ in the second field represents that the password is stored in a shadow file.
  3. UID number: A unique ID assigned for each user. The system identifies a user by its UID number. The root user gets UID 0 which is reserved. UID 1-99 are reserved for predefined accounts. These are also called fake logins. In most Linux systems UID for new users starts from 1000.
  4. GID number: GID is used to identify the group user belongs to. Information about groups is stored in /etc/group file. In Linux, a user can belong in up to 16 groups.
  5. GECOS: stands for General Electric Comprehensive Operating Supervisor. This field allows the admin to store additional information about the user. This field can have multiple entries in a comma-delimited list. Information such as full name, phone number, the designation can be stored in this field.
  6. Home directory: This field contains the absolute path to the user’s home directory. When a user logs in, the system puts him/her directly in his/her home directory.
  7. Login shell: This field is for specifying the program that will run automatically whenever the user logs in. It’s typically a command interpreter (shell).

Create a user

We can use the useradd command to create a new user. Make sure to run the command with root access.

$ useradd Adam 

This creates a user by the name Adam.

Modify GECOS field

To modify the GECOS field for Adam, use usermod command.

$ usermod -c "DevOp expert" Adam

Display entry for a particular user

From the etc/passwd file to get the entry for a single user use grep command.

$ grep Adam /etc/passwd
Grep Command For Adam

As we can see that GECOS field has been successfully updated for user Adam.

We break the values into their respective fields :

  • Login name: Adam
  • Encrypted Password: x (shadow file)
  • UID number: 1001
  • GID number: 1002
  • GECOS: DevOp expert
  • Home directory: /home/Adam
  • Login shell: /bin/sh

Ending words

As a Linux administrator, it is important to know the /etc/passwd file at the back of your hand. Understand what each field means and keep a track of users on the system. To learn more about /etc/passwd file refer to this Wikipedia page for passwd command.

Leave a Reply

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

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages