The Linux/Unix /etc/passwd file

The /etc/password file is very important on Unix systems because it stores information about all the user accounts in the system.

It is readonly, the users can read the file, but not to modify it, unless they have superuser priviledges.

$ ls -l /etc/passwd
-rw-r--r-- 1 root root 1667 2012-06-01 17:31 /etc/passwd
$ < /etc/passwd less

The etc/passwd has a separate line for each user. These lines have 7 fields, delimited one from another by colons (:).

Sample /etc/passwd line:

$ < /etc/passwd grep razvan
razvan:x:1000:1000:razvan,,,:/home/razvan:/bin/bash

The fields are in the following order:

username:x:UID:GID:comment_field:home_dir:default_login_shell

  • Username – the username is the user’s login name.
  • x – the x character indicates that the encrypted password is stored in /etc/shadow ; if you see ! instead of x, that means the user is not allowed to login in the system. (usually, the root in Debian based distros is not allowed to login).
  • UID (User ID) – each user has assigned an ID. root has UID 0, the UIDs 1  – 999 are reserved for the system, and the first user you create (usually when installing Linux) in the system has the UID 1000;
  • GID (Group ID) – each group has it’s own ID; the primary group is stored in /etc/group
  • comment field ; also called as GECOS – these field can be empty; it stores information about the user, such as real name, telephone number, room number, etc.
  • Home directory – the path to the user’s homedir ; by default in Linux, the homedir is in /home/username.
  • Login shell – the path to the login shell; usually /bin/bash, but it can also be another application, instead of a shell (ex: /usr/bin/vim)

I recommend you to avoid editing the /etc/passwd file by hand, unless you know what you are doing.

Share and Enjoy

  • Twitter
  • Facebook
  • Google Plus
  • Email
  • RSS
Tagged with: , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*