Where and how are passwords stored on Linux? – Linux Hint

A username with the correct password for a particular account is a basic condition for the user to access the Linux system. The password for all user accounts is stored in a file or database so that the user can be verified when trying to log in. Not every user has the skills and experience to find this file on his system. However, if you have access to a database or file that contains all the user passwords for logging on to Linux, you can easily access the Linux system. Under Linux, when a user enters a username and password to login, the user checks the password entered in different files in the /etc directory.

The /etc/passwd files contain all the important information the user needs to log into the system. To make it easier, the /etc/passwd file saves the user account data. This file is a simple text file that contains a complete list of all users on your Linux system. It contains information about username, password, UID (user ID), GID (group ID), shell and home directory. This file must be readable because many command line utilities are used to match the user ID with the user name. However, you should only have limited rights for superuser accounts or users with superuser rights.

This article shows how and where to store system user passwords in the Linux distribution. We’ve done all the demonstrations at Ubuntu 20.04. However, you can find the /etc/passwd file in any Linux distribution.

Requirements

You must have root privileges to execute administrative commands.

Basic knowledge of the /etc/passwd file

The /etc/passwd file contains information about your system user account. All registered fields are separated by a colon:. The sign.
When you execute the following command, you will see each entry in the /etc/passwd :

The above command provides an overview of all users on your Linux system.
The following type of format is displayed on your terminal screen:
.

Field data /etc/passwd Format
From above image :

Username : Field 1 is the username. The length of the username field is between 1 and 32 characters. It is used when the user logs in. In the example above, khuzdar is a username.
Password : In the example above, the x-symbol indicates that the password is stored in encrypted form in /etc/shadow.
User Identification Number (UID) : Each user must be given an individual identification code. The null UID is assigned to the root user, and user IDs from 1 to 99 are assigned to predefined or standard accounts. Additional UIDs from 100 to 999 are assigned to system administration accounts or groups. In the figure above, the user ID is 1001.
Group identification (GID) : The following field stands for group identification. The GID is stored in /etc/group. Based on the above example, the user belongs to the group id 1001.
User ID Information : The following field is reserved for comments. In this field you can add some extra information about the specified user, for example the full name of the user, the phone number, etc.. In the example above, however, the telephone number is not provided by the user.
Home directory : This field displays the location of the home directory associated with the current user. If the specified folder does not exist, it will be displayed with /. The image above shows the location of a selected user in the home directory, which is home/kbuzdar.
Command Post: By default, the absolute path is the shell or the /bin/bash command. It’s called a shell. For example, the system administrator uses an illogical shell. It acts as a replacement shell for system user accounts. If the shell is on its way to /sbin/nologin and the user wants to connect to Linux directly, the /sbin/nologin shell will close or disconnect it.

Find a user in /etc/passwd

You can search for a specific user in the /etc/passwd file with the grep command. For example, if we want to search for the username kbuzdar in the /etc/passwd file using the following syntax, we can easily and quickly search for the specified user :

$ grep Username /etc/passwd

The above syntax is modified as follows:

$ grep kbuzdar /etc/passwd

or…

$ grep -w ‘^kbuzdar’ /etc/passwd

Permissions to view in /etc/passwd

As mentioned above, all users other than root must be able to read the rights in /etc/passwd, and the owner must be a superuser or root.
To check the read permissions of the file, enter the following:

The terminal displays the following output example:
.

Reading the /etc/passwd file

You can read the /etc/passwd file on your Linux system with the following bash-script, or you can directly execute what is written below while the loop commands are on the terminal.
Create a text file and insert the following code into this file:

#! /bin/bash
# only seven fields in /etc/passwd are stored as $f1,f2…,$f7!

while IFS=: reads -r f1 f2 f3 f4 f5 f6 f7
do
echo User $f1 uses the $f7 shell and stores the files in the $f6 folder.
does < /etc/passwd

Using the while loop, the seven fields are read and then the content of the file is displayed iteratively on the terminal.
Save the above file as readfile.sh.

Now execute the above file with the following command:

Study /etc/ ghost file

The /etc/shadow file contains all your encrypted passwords, which are stored in this file and can only be read by root users.
To display the content, execute the following command:

You can see all passwords in encrypted form:
.

Conclusion

In the article above we saw all the user account information and passwords stored in the /etc/passwd file on a Linux system. You can read this file, but only root users have write access. We also saw all the encrypted passwords stored in /etc/shadow. You can also consult the /etc/group file for detailed information about the user group.

Related Tags:

linux store password for script,linux get password of current user,old linux password hash,linux password hash structure,shadow-utils component,what command will show your path in linux,password security in linux,linux shadow file vulnerability,etc/shadow file fields in linux,linux store password securely,linux password encryption,linux user security,linux mint 19.3 tweaks,linux mint tweak tool,linux mint tips project,easy linux tips for beginners,linux mint minimal install,linux blogspot,1.Generally linux has drivers for everything known to man, but becuase of proprietary interference or hardware is not used anymore, you may still be able to …2.Message of the day if the screen you see when you log into the command line. Usually if s short and mundane, You may want to jazz it up a little bit with …3.After compiling a program that is a replacementment/upgrade version to existing software you might get a library conflict. That happened to me . Had a …,1.Generally linux has drivers for everything known to man, but becuase of proprietary interference or hardware is not used anymore, you may still be able to …,2.Message of the day if the screen you see when you log into the command line. Usually if s short and mundane, You may want to jazz it up a little bit with …,3.After compiling a program that is a replacementment/upgrade version to existing software you might get a library conflict. That happened to me . Had a …,linux password history setting,clear opasswd,system-auth ac remember,nis password history,suse linux password history,ensure password hashing algorithm is sha-512,where are passwords stored in linux,secure method for password storage in linux,how to access passwords on linux,get password file linux,password salting linux,linux user password list,linux password manager