What is /etc/passwd File in linux

The /etc/passwd is an important text-based file in every Linux operating system which basically acts like a database for users. It contains information like username, user id, etc related to every user existing on the system. To open the file use command:

Whenever a new user is created a new line is added to this file, which looks like this:

username : password : UID : GID :GECOS : home directory :shell

As you can see it has 7 columns separated by the colon ( : ) symbol. username : password : UID : GID :GECOS : home directory :shell

/etc/passwd file format

  1. Username: This field contains the name of the user which is used while logging into the system. The length of this field lies between 1 and 32

  2. Password: This field contains the password in an encrypted format. The x character indicates that the hash is written in /etc/shadow file.

  3. UID: It stands for "user Identifier". UID is used to identify users within the system and also determine which system resource the user can access.UID for every user is always Unique.UID 0 is reserved for the root user. Generally, UID (1000 ...60000 )is used to identify regular users.

  4. GID: This field contains the primary group ID (stored in /etc/groups). Generally, it is the same as UID.

  5. GECOS: It stands for “General Electric Comprehensive Operating System". It is basically a comment field. This field is used to store extra information about the users like full name, phone no, etc.

  6. Home directory: This field contains the absolute path to the directory the user will be in when they log in. In the above example, the home directory of the user is /home/sujata

  7. Shell: This field contains the name of the default shell associated with the user. Here we are using /bin/sh as the default shell. The new user’s login shell is set to the one specified in the /etc/default/useradd file by default .

    If the field contains values /bin/false or /usr/sbin/nologin it means shell access is not allowed.

/etc/passwd File permission

This file can be modified by the root or any users with sudo privileges directly using any text editor. The file permission assigned is 644. To see the file permission for this file you can run the command: ls -l /etc/passwd

Thank you for reading!! ~Sujata Kumari

Great initiative by the #trainwithshubham community. Thank you Shubham Londhe

#devops #90daysofdevops