Skip to content

Instantly share code, notes, and snippets.

@teemuy
Last active September 16, 2017 09:43
Show Gist options
  • Save teemuy/f011827e709daa2e580d5e934bee347b to your computer and use it in GitHub Desktop.
Save teemuy/f011827e709daa2e580d5e934bee347b to your computer and use it in GitHub Desktop.
Shell alias to generate cryptographically strong strings for passwords/keys (needs Python2)
#
# Put the line below in your ~/.profile
# You can then say "genrandstr 10" to get a string of 10 random bytes, base64 encoded.
# Works on macOS, should work on Linux as long as there's Python 2.x installed.
#
alias genrandstr="python2 -c 'import sys,os,base64;print len(sys.argv)==2 and base64.b64encode(os.urandom(int(sys.argv[1]))) or \"Usage: genrandstr <numbytes>\"'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment