/etc/passwd is the key file in any Linux Unix system. Learn fields, formats within /etc/passwd file. Understand the meaning of each field and how it can be set.
In this post, we are going to see the format, the content of
/etc/passwd (will be called as password file henceforth in this post) is a popular and most accessed file when it comes to user in any Linux or Unix based system. Every administrator should be familiar with this file. Rather whenever one starts working on Linux Unix based system this file should be covered during his/her basis learning itself.
The password file is a human-readable file that contains information about users on the system including their encrypted passwords. Some systems don’t have encrypted passwords in this file if /etc/shadow file is generated. Typical
/etc/passwd file looks like below :
# cat /etc/passwd
----- output truncated -----
Since its normal text file, commands like cat, more will work without any issue on it.
/etc/passwd file permission is 644 i.e.
-rw-r--r-- and ownership
root:root. Means file is world-readable and only root users can edit it. However, it is not recommended it manually.
If you observe the above file, it has values separated by colons
:. Each row is one entry. One entry is for one user. For every user (row) there are 7 fields defined separated by a colon. Those seven fields are :
- Encrypted password
- Home directory
Let’s see one by one :
Its user name being used by the user to login. This field gets populated when new users are created on a system using useradd command.
Its password in an encrypted format. In the above example, you see x instead of encrypted password since
/etc/shadow file is generated on the system. The encrypted password is found in
/etc/shadow file in such case.
# cat /etc/shadow
For example, see the above output where the encrypted password for root account can be seen in the second field.
- Read also: Learn how to reset forgotten root password
Its user id. Its unique number assigned to every account on the system. More information on UID can be found here. This can be set using
-u argument in useradd, usermod command. If you want to assign the same UID to some new user which is being used to the old user already then you need to specify
-o in command but this is not recommended.
- Also read: Password file commands
Its group id. Its unique number of groups of which account is member of. GID is created on the system with groupadd command. More information on GID can be found here. This can be set using
-g argument in
This field is introduced to have some descriptions against the account. This is purely for humans to identify/understand what related account is or to whom it belongs to. In the above example, the “ROOT account” is the description defined for the root users. This can be the name of the person or name of application etc. This can be set using
-c argument in
Its a directory where normally user lands into when he/she login. The home directory is where the user’s history file, profile, etc basic account stuff resides. Every user is recommended to have a unique directory. In the above example /root is defined as the home directory for the root account. This can be set using
-d argument in useradd, usermod command. If the directory does not exist on server then -m can be accompany
-d option so that the directory will be created automatically.
This is a shell that will be spawn when the user successfully logs in. In the above example
/bin/bash is shell defined for the root account. This can be set using
-s argument in