Skip to content

Instantly share code, notes, and snippets.

@hypnoglow
Last active September 23, 2023 19:41
Show Gist options
  • Save hypnoglow/363ebe23a72c198edbbd9e1601984dd3 to your computer and use it in GitHub Desktop.
Save hypnoglow/363ebe23a72c198edbbd9e1601984dd3 to your computer and use it in GitHub Desktop.
Bash script to generate secure random password

Usage:

  1. Save this script to gen-password.sh file

  2. Make it executable:

    chmod +x ./gen-password.sh
    
  3. [OPTIONAL] Place it somewhere in your $PATH, e.g.

    sudo mv ./gen-password.sh /usr/local/bin/
    
  4. Run it. Optional argument is the length of the password:

    gen-password.sh 32
    
#!/bin/bash
LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c ${1:-16}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment