(Or at least pseudorandom strings…)
Base64 character set, with openssl
openssl rand -base64 LENGTH | tr -d '\n'tr -d '\n' strips the trailing newline
Ex:
openssl rand -base64 18 | tr -d '\n'
# aHT+O9wbqNCDpBE5wD8cYvIwWith typical shell utils only
Basic format
tr -dc 'CHARACTER_SET' < /dev/urandom | head -c LENGTHPassing -dc drops all chars not in the designated set
Examples
20-character alpha-numeric password
tr -dc '[:alnum:]' < /dev/urandom | head -c 20
# FIlex5AKDDacPkgQ2L7M10-digit random US phone number I guess
tr -dc '[:digit:]' < /dev/urandom | head -c 10
# 539253125130-character password with letters, numbers, and typical punctuation characters (sans-quotes)
tr -dc '[:alnum:]!#%&()*+,-./:;<=>?@[\]^_{|}~' < /dev/urandom | head -c 30
# k}FrTv!XdZ%BOKYhX_F7^%kzfby!]h