Computer Tips - Linux: How can I generate a random password

Date: 2000may29 Update: 2025jul1 OS: Linux Language: bash Q. Linux: How can I generate a random password A. This chain of Linux commands does the trick:
$ head -c10 /dev/random | base64 | sed -e 's/=$//'
Example output:
jlFUjmNqP/E
Change -c10 to -c20 (for example) get more characters. This is pretty good but there is little punctuation in the password. Only upper and lowercase letters, digits, plus and slash. If you have Wireguard installed you can do:
$ wg genkey | sed -e 's/=$//'
Example output:
gCHmUvkrxM43/Ey+Rea+v6hd0ogvj6zlYE2Oyf0SS3g
This is also a base64-encoded random key.