Linux: Generate random password

From RHS Wiki
Jump to navigation Jump to search
# Using date
date +%s | sha256sum | base64 | head -c 32 ; echo

# Using urandom
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
</dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo "" # Left hand will let you write password with one hand



# Using OpenSSL
openssl rand -base64 32

# Using tr
tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1

# Using strings
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo

# Using dd
dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev