Last active
May 21, 2018 07:27
-
-
Save ovidiucp/deacc9010445ccfa8307f81b6348b3a0 to your computer and use it in GitHub Desktop.
Generate random password of specified length (default 12 characters)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this file in your ~/.bashrc. To invoke type in the command line: | |
# | |
# genpasswd | |
# | |
# The default password length is 12 characters. If need it longer: | |
# | |
# genpasswd 24 | |
function genpasswd() { | |
local numchars=$1 | |
if [ -z "$numchars" ]; then | |
numchars=12 | |
fi | |
numchars=$(expr $numchars + 1 ) | |
numbytes=$(expr $numchars + 20 ) | |
openssl rand -base64 $numbytes | \ | |
xargs echo | \ | |
sed -e 's%/%%g' -e 's%=%%g' -e 's%\+%%g' -e 's% %%g' | \ | |
tail -c -$numchars | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment