/etc/passwdfile is one of the most important files as it possess all the necessary details about every account in the Linux system. In this article, we will learn about
/etc/passwdfile in more depth.
File permissions on
In order to view file permissions on
/etc/passwdfile, you can execute
ll /etc/passwdas follows:
You can clearly observe that, this file is open to be read by all, but is only writable by root or superuser.
MyLinuxBox root ~ > ll /etc/passwd -rw-r--r--. 1 root root 1718 Jun 6 12:01 /etc/passwd
/etc/passwd file contents
/etc/passwdmaintains the information about each and every user that can use the system. Every time a new user account is created, the user account details are stored in the same file. Whenever some user attempts for a login to the system, the
gettyprocess validates the user, whether the user is legitimate or not, using
/etc/shadowfor the password validation) file.
/etc/passwdis a text file that contains one separate line entry, delimited by a colon (:), for each user account configured in the system, as shown below:
Let us consider entry for the user '
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin ... ... ... sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin mandar:x:500:500:Mandar Shinde:/home/mandar:/bin/bash mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash nagios:x:501:501::/home/nagios:/bin/bash
mandar', to get in the depth of the file contents:
mandar : x : 500 : 500 : Mandar Shinde : /home/mandar : /bin/bash |---1---|--2--|---3---|---4---|---------5-------|-------6--------|-----7----|
As I said, there is a separate entry on a separate line in the
/etc/passwordfile, for each user in the system, and each entry being delimited with a colon (:). For better understanding, I've created the fields across each colon and numbered each of the fields, in this way, there are total 7 fields generated. Let us study each field one by one:
- Username field: This field denotes the User (or User Account) Name. According to the man page of
useraddcommand, "Usernames may only be up to 32 characters long". This username must be used at the time of logging in to the system.
- Password field: Second field is the Password field, not denoting the actual password though. A 'x' in this field denotes the password is encrypted and saved in the
- UID field: Whenever a new user account is created, it is assigned with a user id or UID (UID for the user '
mandar' is 500, in this case) and this field specifies the same.
- GID field: Similar to the UID field, this field specifies which group the user belongs to, the group details being present in
- Comment/Description/User Info field: This field is the short comment/description/information of the user account (For this example, user account '
mandar' belongs to the user
Mandar Shinde, hence this comment).
- User Home Directory: Whenever a user logs in to the system, he is taken to his Home directory, where all his personal files reside. This field provides the absolute path to the user's home directory (
/home/mandarin this case).
- Shell: This field denotes, the user has access to the shell mentioned in this field (user '
mandar' has been given access to
/etc/passwdfile, as below:
To check this, run the script as follows:
#!/bin/bash grep -w "$1" /etc/passwd | while IFS=':' read USR PSWD USRID GRPID DESC HOMEDIR SHL do echo -e "\t\tUsername : $USR UID : $USRID GID : $GRPID Description : $DESC Home Directory : $HOMEDIR Shell : $SHL" done
That's all about this article, stay tuned for many more of them.
MyLinuxBox root ~ > ./userdetail.sh mandar Username : mandar UID : 500 GID : 500 Description : Mandar Shinde Home Directory : /home/mandar Shell : /bin/bash MyLinuxBox root ~ > ./userdetail.sh nagios Username : nagios UID : 501 GID : 501 Description : Home Directory : /home/nagios Shell : /bin/bash