Understanding the /etc/passwd file in Linux

Home > Search
  by

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 = UID
  • Field 4 = GID
  • Field 5 = Comment (empty by default)
  • Field 6 = Home directory
  • Field 7 = Default shell

 

The cat command can be used to view the /etc/passwd file.

[root@server1 ~]# cat /etc/passwd | grep user1
user1:x:1002:1002::/home/user1:

 


Field 1 (Username)

The first field in the /etc/passwd file is username (user1 in this example). The usermod command can be used to change the username.

[root@server1 ~]# cat /etc/passwd
user1:x:1002:1002::/home/user1:
. . .

 


Field 2 (Password)

The second field in the /etc/passwd file will have an "x", because passwords are not stored in the /etc/passwd file. Instead, 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.

[root@server1 ~]# cat /etc/passwd
user1:x:1002:1002::/home/user1:
. . .

 


Field 3 (UID)

The third field in the /etc/passwd file is the UID (1001 in this example). The usermod -u command can be used to change the UID.

[root@server1 ~]# cat /etc/passwd
user1:x:1001:1002::/home/user1:
. . .

 


Field 4 (GID)

The fourth field in the /etc/passwd file is the GID (1002 in this example). The usermod -g command can be used to change the GID.

[root@server1 ~]# cat /etc/passwd
user1:x:1001:1002::/home/user1:
. . .

 


Field 5 (Comment)

The fifth field in the /etc/passwd file is for comments. By default, accounts will not have a comment. The usermod -c command can be used to add or change the comment.

[root@server1 ~]# cat /etc/passwd
user1:x:1001:1002::/home/user1:
. . .

 


Field 6 (Home Directory)

The sixth field in the /etc/passwd file is the users home directory (/home/user1 in this example). The usermod -d command can be used to change the home directory.

[root@server1 ~]# cat /etc/passwd
user1:x:1001:1002::/home/user1:
. . .

 


Field 7 (Default Shell)

The seventh field in the /etc/passwd file is the users default shell (empty in this example). The usermod -s command can be used to change the default shell.

[root@server1 ~]# cat /etc/passwd
user1:x:1001:1002::/home/user1:
. . .

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments