Last Updated : 23 Jul, 2025
The /etc/passwd file is the most important file in Linux operating system. This file stores essential information about the users on the system. This file is owned by the root user and to edit this file we must have root privileges. But try to avoid edit this file. Now let's see actually how this file look
This file contains one entry per line. That means it stores one user's information on one line. The user information contains seven fields and each field is separated by the colon ( : )symbol. Each entry in the /etc/passwd file looks like this:
Now let's understand each field one by one:Now we have understood the file structure of the /etc/passwd file now let's see one example of this file. You can view the content of file using the cat file like:
cat /etc/passwd
We can see that there are many users with all information.
To search for a specific user, we can use the grep command. Now for example to get information about the user Nishant we can use the following command:
grep nishant /etc/passwdCheck /etc/passwd file permission
The normal users have only read permissions to the /etc/passwd file. The only root user can write into this file. To see the permissions of /etc/passwd file, we can use the ls command as follows:
ls -l /etc/passwd
The output will be
We can see that the permissions of the file /etc/passwd are rw-r--r--. This means the root user has read and write access and other groups and user have read-only access to the file.
To get more details like size, modify the time of this file we can use the stat command:
stat /etc/passwdReading /etc/passwd file:
We can read the /etc/passwd file more user-friendly by using the while loop and IFS separator. A while loop is used to iterate through the file, and IFS is a special variable is used to separate the string by a specific character.
#!/bin/bash # using while loop to iterate through file while IFS=: read -r f1 f2 f3 f4 f5 f6 f7 do echo "User $f1 use $f7 shell and stores files in $f6 directory." done < /etc/passwd
After using this script, we get the following output:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4