Bash

Generate a Random Password

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Three approaches: pwgen (purpose-built), openssl (universally available), /dev/urandom + tr (zero deps). Pick by what's installed.
Bash
Raw
# openssl — universally available
openssl rand -base64 32                # base64 (with + / =)
openssl rand -hex 16                   # 32-char hex

# /dev/urandom + tr — zero deps, customize alphabet
LC_ALL=C tr -dc 'A-Za-z0-9!@#$%^&*' </dev/urandom | head -c 24; echo

# pwgen — readable, multi-word
pwgen -s 20 1                          # 20 chars, secure, 1 password
pwgen -sy 24 5                         # 5 passwords with symbols

# Diceware-style passphrase (needs a wordlist)
shuf -n 5 /usr/share/dict/words | paste -sd '-' -

# UUID (good for tokens, not passwords)
cat /proc/sys/kernel/random/uuid       # cf5d3aa9-...
uuidgen
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.