/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
file. /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
root:x:0:0:ROOT account:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
myuser:x:513:520:Test User:/home/myuser:/bin/bash
----- output truncated -----
Since its normal text file, commands like cat, more will work without any issue on it.
By default /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 :
- Username
- Encrypted password
- UID
- GID
- Comment
- Home directory
- Shell
Let’s see one by one :
Username
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.
Encrypted Password
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
root:$6$FCGlEAUb$nRMJdwjadnw7.OL6L2oxeMQzM445gv0NK1AfjpjSMyth5JHXolCQnhA0:17075:0:99999:7:::
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
UID
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
GID
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 useradd
, usermod
command.
Comment
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 useradd
, usermod
command.
Home Directory
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.
Shell
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 useradd
, usermod
command.
IT’S NOW OR NEVER (Sidemen Gaming)
¡NOS CONVERTIMOS EN BOMBEROS 🔥🚒 ELTROLLINO, MIKECRACK Y TIMBAVK