How to create SHA512/SHA256/MD5 password hashes on command line
Method 1- Using mkpasswd
On Ubuntu you need to install whois package to get mkpasswd utility.
root@ansible-controller:~/# apt-get install whois
root@ansible-controller:~/# mkpasswd -m sha-512
Password:
$6$KU2P9m78xF3n$noEN/CV.0R4qMLdDh/TloUplmJ0DLnqi6/cP7hHgfwUu.D0hMaD2sAfxDT3eHP5BQ3HdgDkKuIk8zBh0mDLzO1
Other Options -
root@ansible-controller:~/# mkpasswd — help
Usage: mkpasswd [OPTIONS]… [PASSWORD [SALT]]
Crypts the PASSWORD using crypt(3).
-m, — method=TYPE select method TYPE
-5 like — method=md5
-S, — salt=SALT use the specified SALT
-R, — rounds=NUMBER use the specified NUMBER of rounds
-P, — password-fd=NUM read the password from file descriptor NUM
instead of /dev/tty
-s, — stdin like — password-fd=0
-h, — help display this help and exit
-V, — version output version information and exit
If PASSWORD is missing then it is asked interactively.
If no SALT is specified, a random one is generated.
If TYPE is ‘help’, available methods are printed.
Method 2- Using openssl
root@ansible-controller:~/# openssl passwd -6
Password:
Verifying — Password:
$6$SX8O9xVd1d/WX2hm$vh9RI2WCnh1BKwmHU2QHX5/ZMwH45zLpVe5v7EykPvjtiNGeYqje9GH2l/dZruVP0kYyPecJRGz1XfYpLERHh0
Other options -
root@ansible-controller:~/# openssl passwd — help
Usage: passwd [options]
Valid options are:
-help Display this summary
-in infile Read passwords from file
-noverify Never verify when reading password from terminal
-quiet No warnings
-table Format output as table
-reverse Switch table columns
-salt val Use provided salt
-stdin Read passwords from stdin
-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
-crypt Standard Unix password algorithm (default)
-rand val Load the file(s) into the random number generator
-writerand outfile Write random data to the specified file
Hope you like the tutorial. Please let me know your feedback in the response section.