quickly generate an encrypted password

Hi everybody !  Here’s a quick method for generating encrypted passwords that are suitable for things like /etc/passwd .  I realise that this isn’t terribly complex, but honestly, I always forget how to do this until I actually need to do it – so here’s a reminder for all of us. 🙂

#!/bin/bash

if [ "x$1" == 'x' ]; then
echo "USAGE: $0 'password'"
exit 1
fi


# Get an md5sum of the password string; this is used for the SHA seed.
md5=$( echo $1 | md5sum )
extract="${md5:2:8}"


# Calculate the SHA hash of the password string using the extracted seed.
mkpasswd -m SHA-512 "$1" "$extract"
exit $?

Author: phrawzty

I have a computer.

2 thoughts on “quickly generate an encrypted password”

  1. I have named the script as password..when it is run.it is throwing below error
    USAGE: ./password ‘ ‘

    Like

  2. Mahesh :
    I have named the script as password..when it is run.it is throwing below error
    USAGE: ./password ‘ ‘

    Hi Mahesh,

    You need to give it the string (i.e. password) that you wish to encrypt – it will not generate a password for you, only the hash of the password you specify.

    Like

Leave a comment