With openssl
In macOS, it's very simple, using openssl
which is a native already installed package (as mentioned in the apple article shared in @Tetsujin’s answer):
I'm going here to explain how to use in details:
openssl passwd -6
To show what crypto hashes are supported:
openssl passed -help
- Check
Cryptographic options:
Input options:
-in infile Read passwords from file
-noverify Never verify when reading password from terminal
-stdin Read passwords from stdin
Output options:
-quiet No warnings
-table Format output as table
-reverse Switch table columns
Cryptographic options:
-salt val Use provided salt
-6 SHA512-based password algorithm
-5 SHA256-based password algorithm
-apr1 MD5-based password algorithm, Apache variant
-1 MD5-based password algorithm
-aixmd5 AIX MD5-based password algorithm
Random state options:
-rand val Load the given file(s) into the random number generator
-writerand outfile Write random data to the specified file
Provider options:
-provider-path val Provider load path (must be before 'provider' argument if required)
-provider val Provider to load (can be specified multiple times)
-propquery val Property query used when fetching algorithms
Using python
Refs
Execution
One-liner:
python3 -c "from passlib.hash import sha512_crypt; import getpass; swd = getpass.getpass('Password:'); print(sha512_crypt.hash(swd))"
output format
$6$rounds=656000$9NGDC8UzAGWWIdNP$Xltp2/G/Q6geYDe07q2l426oV7b.nqjPpc7t6GZVbdZwM7XQrCDdwNkUCBvjGMZmj9qnbZ.tkmnXlxN04YY.s.
- Note that the output from this differs from the one of OpenSSL. It should work in things like
ansible
, and I suppose other usages. Because if the OS supports crypt()
then passlib
will use that sys call
. There is a round param and others, check the reference above.
Requirements
- Install the
passlib
library:
pip3 install --user passlib
slappasswd
no SHA512
slappasswd
doesn't support SHA512
man slappasswd
-h "scheme"
If -h is specified, one of the following RFC 2307 schemes may be specified: {CRYPT}, {MD5}, {SMD5}, {SSHA},
and {SHA}. The default is {SSHA}.
Note that scheme names may need to be protected, due to { and }, from expansion by the user's command
interpreter.
{SHA} and {SSHA} use the SHA-1 algorithm (FIPS 160-1), the latter with a seed.
{MD5} and {SMD5} use the MD5 algorithm (RFC 1321), the latter with a seed.
{CRYPT} uses the crypt(3).
{CLEARTEXT} indicates that the new password should be added to userPassword as clear text. Unless
{CLEARTEXT} is used, this flag is incompatible with option -g.