Last active
March 1, 2021 15:23
-
-
Save ksuderman/49dba030fed64e52426910cca5b6f0d4 to your computer and use it in GitHub Desktop.
Generate a random string. Useful for generating system passwords
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
secret=`cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;` | |
echo $secret | |
# If tr complains about illegal byte sequences it is because tr can not handle UTF-8 characters. | |
# The solution is to specify the C locale for tr | |
secret=`cat /dev/urandom | LC_ALL=C tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;` | |
echo $secret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment