linux,

Generate SHA512 password hash with a salt from the CLI

Apr 26, 2022 · 1 min read · Post a comment
Generate SHA512 password hash with a salt from the CLI

Personally, the only time I’ve been generating a SHA512 password hashes was when I was working with the Ansible builtin user module, sipmly because I needed to commit a password hash for a new Linux user. Although I wouldn’t consider it as an optimal solution (not even close), let’s see how to create one.

Prerequisites

  • Shell environment

Solutions

Solution 1. Use mkpasswd

Step 1. Install mkpasswd.

sudo apt install whois

Step 2. Generate SHA512 password hash with a salt.

mkpasswd --method sha-512 <SOME_PASSWORD_HERE>

Note(s):

  1. If you don’t add parameter -S, --salt=<SOME_STRING_HERE>, it will use a random salt value.
  2. If you want to keep it OS agnostic (since mkpasswd it’s not available to MacOS and Windows, although you could install it via gem or npm), use Docker. For instance:
    docker run -it --rm alpine mkpasswd --method=sha-512 <SOME_PASSWORD_HERE>
    

Solution 2. Use openssl

Step 1. Open Terminal and run the following command:

openssl passwd -6 -salt <SOME_SALT_HERE>

Note. The SALT string could be any random string, just make sure not to be a short one.

Conclusion

If you can think of any other alternative solution, please do let me know in the comment section below. On a side note, follow our official channel on Telegram.