You are on page 1of 3

Method 1 (md5, sha256, sha512)

openssl passwd -6 -salt xyz yourpass

Note: passing -1 will generate an MD5 password, -5 a SHA256 and -6 SHA512 (recommended)

Method 2 (md5, sha256, sha512)


mkpasswd --method=SHA-512 --stdin

The option --method accepts md5, sha-256 and sha-512

Method 3 (des, md5, sha256, sha512)


As @tink suggested, we can update the password using chpasswd using:
echo "username:password" | chpasswd

Or you can use the encrypted password with chpasswd. First generate it using this:
perl -e 'print crypt("YourPasswd", "salt", "sha512"),"\n"'

Then later you can use the generated password to update /etc/shadow:
echo "username:encryptedPassWd" | chpasswd -e

The encrypted password we can also use to create a new user with this password, for example:
useradd -p 'encryptedPassWd' username

mkpasswd -m sha-512 -S saltsalt -s <<< YourPass


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.D0hMaD2sAfxDT
3eHP5BQ3HdgDkKuIk8zBh0mDLzO1
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/ZMwH45zLpVe5v7EykPvjtiNGeYq
je9GH2l/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.

You might also like