/etc/passwd is key file in any Linux Unix system. Learn fields, formats within /etc/passwd file. Understand meaning of each field and how it can be set.
In this post we are going to see format, content of /etc/passwd file. /etc/passwd (will be called as password file henceforth in this post) is 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.
Password file is human readable file which contains information about users on system including their encrypted passwords. Some systems dont 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.
If you observe 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 colon. Those seven fields are :
- Encrypted password
- Home directory
Lets see one by one :
Its user name being used by user to login. This field gets populated when new users is created on system using useradd command.
Its password in encrypted format. In above example you see x instead of encrypted password since /etc/shadow file is generated on system. Encrypted password is found in /etc/shadow file in such case.
# cat /etc/shadow
For example see above output where encrypted password for root account can be seen in second field.
REad also : Learn how to reset forgotten root password
Its user id. Its unique number assigned to every account on 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 same UID to some new user which is being used to 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 group of which account is member of. More information on GID can be found here. This can be set using -g argument in useradd, usermod command.
This field is introduced to have some description against account. This is purely for humans to identify/understand what related account is or to whom it belongs to. In above example, “ROOT account” is the description defined for root user.This can be name of person or name of application etc. This can be set using -c argument in useradd, usermod command.
Its a directory where normally user lands into when he/she login. Home directory is where user’s history file, profile etc basic account stuff resides. Every user is recommended to have unique directory. In above example /root is defined as home directory for 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 directory will be created automatically.
This is shell which will be spawn when user successfully logs in. In above example /bin/bash is shell defined for root account. This can be set using -s argument in useradd, usermod command.