Linux Files - Understanding the /etc/passwd file

by
Jeremy Canfield |
Updated: November 06 2023
| Linux Files articles
The /etc/passwd is a colon separated list of attributes of a user account. A very similar file is /etc/shadow. The /etc/passwd file has the following fields.
- Field 1 = username
- Field 2 = password
- Field 3 = numeric user ID (UID)
- Field 4 = numeric default group ID (GID)
- Field 5 = Comment (empty by default)
- Field 6 = Users home directory (e.g. /home/john.doe)
- Field 7 = Users default shell (e.g. /bin/bash)
For example, let's say one of the lines in /etc/passwd contains the following.
- Field 1 = username = john.doe (The usermod command can be used to change the username)
- Field 2 = password = x to indicate the user has a password (the password is not "x") - passwords are stored in /etc/shadow. The passwd command can be used to create a new encrypted password. The usermod -p command can be used to create a new cleartext password.
- Field 3 = numeric user ID = 1002 (The usermod -u command can be used to change the UID)
- Field 4 = numeric default group ID = 2002 (The usermod -g command can be used to change the GID)
- Field 5 = Comment = empty / no comment (The usermod -c command can be used to add or change the comment)
- Field 6 = Users home directory = /home/john.doe (The usermod -d command can be used to change the home directory)
- Field 7 = Users default shell = /bin/bash (The usermod -s command can be used to change the default shell)
john.doe:x:1002:2002::/home/john.doe:/bin/bash
There are a few commands that can be used to determine if a user account exists.
- The cat command to read the /etc/passwd file (this article)
- The id command
- The getent passwd command
Did you find this article helpful?
If so, consider buying me a coffee over at