Encrypted passwords on Linux

From UVOO Tech Wiki
Revision as of 18:02, 30 March 2022 by Busk (talk | contribs) (Created page with "https://unix.stackexchange.com/questions/81240/manually-generate-password-for-etc-shadow ``` Method 1 (md5, sha256, sha512) openssl passwd -6 -salt xyz yourpass Note: passing...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

https://unix.stackexchange.com/questions/81240/manually-generate-password-for-etc-shadow

Method 1 (md5, sha256, sha512)
openssl passwd -6 -salt xyz  yourpass
Note: passing -1 will generate an MD5 password, -5 a SHA256 and -6 SHA512 (recommended)

Method 2 (md5, sha256, sha512)
mkpasswd --method=SHA-512 --stdin
The option --method accepts md5, sha-256 and sha-512

Method 3 (des, md5, sha256, sha512)
As @tink suggested, we can update the password using chpasswd using:

echo "username:password" | chpasswd 
Or you can use the encrypted password with chpasswd. First generate it using this:

perl -e 'print crypt("YourPasswd", "salt", "sha512"),"\n"'
Then later you can use the generated password to update /etc/shadow:

echo "username:encryptedPassWd" | chpasswd -e
The encrypted password we can also use to create a new user with this password, for example:

useradd -p 'encryptedPassWd'  username