All of the Linux distributions stores user information in a central file named /etc/passwd. The /etc/passwd file is a simple text based flat database which contains the current Linux system users with information like user name, user ID, default shell etc. Decades ago the /etc/passwd was also containing the user password hashes but because of the security reasons the password hashes moved into the file named /etc/shadow.
List /etc/passwd Content
The /etc/passwd file content can be printed by using the cat command like below. As a simple text file it can be easily printed to the terminal or opened with a file editor. Reading the /etc/passwd file do not requires extra privielege for a default user. But regular user can not change or write into /etc/passwd file without root privielege.
cat /etc/passwd
Meaning of the /etc/passwd File Fields
ismail:x:1000:1000:İsmail Baydan,,,:/home/ismail:/bin/bash
- Username: ismail is the username and used to login system via GUI, bash, SSH, etc. The username can be between 1 and 32 characters. Letters and numbers can be used for a user name but the user name can not start with a number.
- Password: x is the password part of the user. But x is just a placeholder. The actual password is stored in /etc/shadow file. The only root can read this password file.
- User ID (UID): Each user has a unique user id to represent the user numerically. UID 0 is used by root by default. UID 1-99 preserved for predefined accounts like news,lp,man,backup etc. UID 100-999 are reserved for system accounts like avahi, saned, sssd etc. Normal user ID starts from 1000.
- Group ID (GID): Every user has a primary group which is generally the user own group. The GID specifies the primary ID for the user. Group names and ID’s located under /etc/group file.
- User Info: This is a comment field used to store some information data about the user like full name, phone number, room number, etc.
- Home Directory: The home directory specifies the user default home directory which is used to store user private data like downloads, documents, pictures, etc. The home directory for a user generally created under the /home like /home/ismail.
- Shell: Linux provides multiple shells named bash, ksh, csh and the shell information provides the default user shell absolute path.
Grep User Names From /etc/passwd
As a simple text file and contains the usernames the /etc/passwd can be grepped to list only user names in a Linux system. The user names listed line by line.
grep -oE '^[^:]+' /etc/passwd
root daemon bin sys sync games man lp ... gnome-initial-setup gdm ismail systemd-coredump lightdm xrdp ali ahmet mysql sshd sddm
Change User Default Shell via /etc/passwd
The /etc/passwd stores each user default shell binary path. In generaly /bin/bash is the most popular shell and used default shell for the user. The default shell of a specific user can be changed via the /etc/passwd file. Just change the last column of the user into the shell you want. In the following example the user ismail default shell changed into the ksh.
ismail:x:1000:1000:İsmail Baydan,,,:/home/ismail:/bin/ksh
Change User Home Directory via /etc/passwd
The user home directory stored in /etc/passwd too. The user home directory can be changed via this file. Just put the new home directory path before the default shell. In the following example the user ismail default home directory changed into the /mnt/ismail.
ismail:x:1000:1000:İsmail Baydan,,,:/mnt/ismail:/bin/bash