How to create sha-512 password hashes on Mac for CentOS?

I need to generate password hashes on Mac for CentOS. I can generate sha with echo foopass | shasum -a 512, but as I've understood password hashes are more just one sha application.

I've found some one-liners, but looks like they use system crypt function (I've tried some myself), which on Mac only supports DES.

Maybe there are some already implemented on macOS this way?


Solution 1:

I decided to use Docker: run image of system where I need to create pass and then run Python code suggested in one-liners.

I got Docker Desktop already, just in case instructions for install.

Then when Docker Desktop running in shell:

$ docker run -it centos:7

Inside running container I decided to also check if hash is generated correctly, so first adding user, then output of it's hash, then generating hash for the given specific salt then finally generating needed number of hashes (for same password):

# adduser test
# passwd test         
Changing password for user test.
New password: 123
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 123
passwd: all authentication tokens updated successfully.
# cat /etc/shadow | grep test
test:$6$msMZIy.A$4TOBPNgnGNE05Ptx0RX8/UY731/n5Vr2ZNUqNTW3OxbPyaOiGrb9kDhSsaZSr91OCKnM6uJs5nynnP3CiMXOk1:18179:0:99999:7:::
# yum install python3

...long output and confirming install with y-s.

# python3
>> import crypt
>> print (crypt.crypt("123","$6$msMZIy.A")) # taking part of grep output
$6$msMZIy.A$4TOBPNgnGNE05Ptx0RX8/UY731/n5Vr2ZNUqNTW3OxbPyaOiGrb9kDhSsaZSr91OCKnM6uJs5nynnP3CiMXOk1
>> exec ('for i in range(30):print (crypt.crypt("neededpass",crypt.mksalt(crypt.METHOD_SHA512)))')
...list of 30 hashes for neededpass with ramdom salt
...
>> exit()
# exit