In Linux, a user is identified using a unique identifier called as user id (UID). Each user belongs to at least one group called the user’s primary group. Like user, a group is also identified with the help of a unique identifier called as group id (GID). UID and GID controls the accessibility of the files and folders in Linux.
Linux maintains the information of all its users in a world readable file /etc/passwd.
# ls -l /etc/passwd -rw-r--r-- 1 root root 1589 Aug 30 16:45 /etc/passwd
This article explains the contents of /etc/passwd file in Linux.
Linux passwd File Entries
Following is typical entry from a /etc/passwd file,
# cat /etc/passwd | grep kam kam:x:502:502:Kam Aggarwal:/home/kam:/bin/bash
Each entry in Linux passwd file corresponds to a user and contains seven fields as shown below.
Field 1: Username
- This contains the user’s login id. This is the username which is used for login.
- Username uniquely identifies a user on a Linux system. We can’t have multiple users with same username.
Field 2 : Password
- This field contains the encrypted password for the user.
- Value ‘x’ in this field indicates that the user password is stored in the /etc/shadow file.
# cat /etc/shadow | grep kam kam:$1$8zowrENV$XL8nvq94dwqU4kTmDlBQk.:15595:0:99999:7:::
- The second field represents the encrypted password for the user ‘kam’
Field 3 : User-Id
- User-Id represents a unique number which is used by the Linux to identify the user.
- There is one to one mapping between the Username and User-Id.
- Every user must be assigned with a unique UID in a Linux system. This applies to all UIDs but ’0′.
- The superuser ‘root’ is assigned with a special UID ’0′. Any user having UID ’0′ has root privileges.
Field 4 : Group-Id
- Group-Id represents a unique number identifying the primary group id for the user.
- Linux maintains the group name and group id mapping in a separate world readable file /etc/group. Following is the entry for GID ’502′ in the group file.
# cat /etc/group | grep kam kam:x:502:
Field 5 : User Information
- This field is used to store the general information about the user, like, user’s full name, contact information etc.
- This field can be left blank.
Field 6 : User’s Home Directory
- This field contains the location of user’s home directory.
# ls -l /home | grep kam drwx------ 3 kam kam 4096 Sep 12 18:20 kam
- User’s home directory contains all user specific configuration files.
- A user is provided full access to it’s home directory. Which means that the user is free to add, modify and delete any file or folder in its home directory.
Field 7 : User’s Shell
- Shell is the first program that a user encounters after logging into a Linux system. Linux comes with several shells.
# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/tcsh /bin/csh /bin/ksh /bin/zsh
- This field stores the user’s default shell.