Are login passwords saved on the machine or only a hash version of the password? If only a hash version of the login password is saved, which hash method is used? In which folder is it stored on the machine? I am using Ubuntu 22.04.
man shadow, which explains how passwords are stored for users:
encrypted password This field may be empty, in which case no passwords are required to authenticate as the specified login name. However, some applications which read the /etc/shadow file may decide not to permit any access at all if the password field is empty. A password field which starts with an exclamation mark means that the password is locked. The remaining characters on the line represent the password field before the password was locked. Refer to crypt(3) for details on how this string is interpreted. If the password field contains some string that is not a valid result of crypt(3), for instance ! or *, the user will not be able to use a unix password to log in (but the user may log in the system by other means).
man 3 crypt we see this explains the encryption:
DESCRIPTION The crypt, crypt_r, crypt_rn, and crypt_ra functions irreversibly “hash” phrase for storage in the system password database (shadow(5)) using a cryptographic “hashing method.” The result of this operation is called a “hashed passphrase” or just a “hash.” Hashing methods are described in crypt(5).
Following, that, we look at
man 5 crypt:
DESCRIPTION The hashing methods implemented by crypt(3) are designed only to process user passphrases for storage and authentication; they are not suitable for use as general-purpose cryptographic hashes. Passphrase hashing is not a replacement for strong passphrases. It is always possible for an attacker with access to the hashed passphrases to guess and check possible cleartext passphrases. However, with a strong hashing method, guessing will be too slow for the attacker to discover a strong passphrase. All of the hashing methods use a “salt” to perturb the hash function, so that the same passphrase may produce many possible hashes. Newer methods accept longer salt strings. The salt should be chosen at random for each user. Salt defeats a number of attacks: 1. It is not possible to hash a passphrase once and then test it against each account's stored hash; the hash calculation must be repeated for each account. 2. It is not possible to tell whether two accounts use the same passphrase without successfully guessing one of the phrases. 3. Tables of precalculated hashes of commonly used passphrases must have an entry for each possible salt, which makes them impractically large. All of the hashing methods are also deliberately engineered to be slow; they use many iterations of an underlying cryptographic primitive to increase the cost of each guess. The newer hashing methods allow the number of iterations to be adjusted, using the “CPU time cost” parameter to crypt_gensalt(3). This makes it possible to keep the hash slow as hardware improves.
By following this chain (
man shadow to
man 3 crypt to
man 5 crypt) we can see that passwords are stored in
/etc/shadow as salted hashed passwords. There are numerous hash mechanisms and methods available so you have to deep-dive into the manpages to really interpret the data in
/etc/shadow to determine which hash mechanism is in use on your environment by default.
In addition to hashed / salted passwords, some are stored in plain text where no one else can read them.
.netrcfile should be located in your home directory and the permissions on the file must be set so that you are the only user who can read it, i.e. it is unreadable to everyone else. It should be set to at least Read (
400), or Read/Write (
For small developers who wish to avoid the complexities of managing passwords with hashing algorithms, the
~/.netrc methodology can be considered. The methodology is used in SSH to automatically log into remote servers.