Skip to content

Instantly share code, notes, and snippets.

@ksuderman
Last active March 1, 2021 15:23
Show Gist options
  • Save ksuderman/49dba030fed64e52426910cca5b6f0d4 to your computer and use it in GitHub Desktop.
Save ksuderman/49dba030fed64e52426910cca5b6f0d4 to your computer and use it in GitHub Desktop.
Generate a random string. Useful for generating system passwords
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