How to create SHA512 password hashes on command line


Python (>= 3.3)

$ python -c 'import crypt,getpass; print(crypt.crypt(getpass.getpass(), crypt.mksalt(crypt.METHOD_SHA512)))'

-or scripted-

$ python -c 'import crypt; print(crypt.crypt("somesecret", crypt.mksalt(crypt.METHOD_SHA512)))'

Python (2.x or 3.x)

$ python -c "import crypt, getpass, pwd; \
             print(crypt.crypt('password', '\$6\$saltsalt\$'))"


Note: $6$ designates sha512. Support for this method of specifying the algorithm is dependent on support in OS level crypt(3) library function (usually in libcrypt). It is not dependent on python version.


$ perl -e 'print crypt("password","\$6\$saltsalt\$") . "\n"'

In these examples the password is the string “password” and the salt is “saltsalt”. Both examples are using $6$ which denotes that you want crypt to use SHA-512.


The password hash can be installed as user password in Linux with:

echo ‘test:$6$saltsalt$9liuUSt9ok/UfOLRNtj/jjfg9JjSE2aqTqA19FkVZUL0XE8xdJeSszpX3zVuQS2K0.I5LeRJCpDQ/wecnxUaM.’ | chpasswd -e

Leave a Reply

Your email address will not be published. Required fields are marked *