As we know on Linux operating systems password are generally stored in "/etc/shadow" file in specific format and there are some formats. Each row in "/etc/shadow" file is a string with 9 fields separated by ':'.
gituser:$6$kURThR6P$YUPkU29r1k2x2zXRU5R6eNYg6/qZv5aIcZreV21Fkgco0Kc609DiWBPlhObrKKqbO9dsU.MrqgpvP0WGU63IV1:17354:0:99999:7:::
- The local username
- Password hash
- Number of days since the start of unix time (01/01/1970) that the password was last changed
- Minimum number of days before the password can be changed
- Maximum number of days before the password must be changed. 99999 means that the user will not be forced to change their password
- Number of days before forcing the password change that the user will be warned.
- The number of days after expiration that the account will be disabled
- Days since the start of unix time that the account has been disabled
- Reserved for future use
The majority of these fields are usually not used by Linux distributions. The most important fields are the user name and hash. The hash field consists of three separate fields. They are separated by"$" and represent :
- Some of these characters represent the cryptographic hash mechanism used to generate the actual hash.
- A randomly generated salt to protect against rainbow table attacks.
- The hash is the result of associating the user's password with the previously stored salt.
-
$1$ --> md5 -
$2a$ --> Blowfish -
$2y$ --> Blowfish, with correct handling of 8 bit characters -
$5$ --> sha256 -
$6$ --> sha512
mkpasswd --method=sha512 --salt=kURThR6P doit0002
python -c "import crypt; print crypt.crypt('doit0002', '\$6\$kURThR6P')"
python3 -c "import crypt; print (crypt.crypt('doit0002', '\$6\$kURThR6P'))"
python3.5 -c "import crypt; print (crypt.crypt('doit0002', '\$6\$kURThR6P'))"
python3.6 -c "import crypt; print (crypt.crypt('doit0002', '\$6\$kURThR6P'))"
[gituser@localhost ~]$ sudo cat /etc/shadow | grep gituser
gituser:$6$kURThR6P$YUPkU29r1k2x2zXRU5R6eNYg6/qZv5aIcZreV21Fkgco0Kc609DiWBPlhObrKKqbO9dsU.MrqgpvP0WGU63IV1:17354:0:99999:7:::
[gituser@localhost ~]$ python -c "import crypt; print crypt.crypt('doit0002', '\$6\$kURThR6P')"
$6$kURThR6P$YUPkU29r1k2x2zXRU5R6eNYg6/qZv5aIcZreV21Fkgco0Kc609DiWBPlhObrKKqbO9dsU.MrqgpvP0WGU63IV1
PS : Thanks to Hansel --> https://www.aychedee.com/2012/03/14/etc_shadow-password-hash-formats/