Generate passwords from CLI

· Alberto's Blog!

How to generate random passwords from the command line.

Problem #

Simple and easy method for generating random passwords from the command line.

Solution #

Use the command below:

1LC_ALL=C </dev/urandom tr -cd '[:alnum:]' | head -c 32

Explanation #

Generates a random string, remove non-alphanumeric characters and print the first 32 characters.

Adjust the length of the password by changing the number after -c in head -c 32.

Add symbols by adding [:punct:] to the character class in tr -cd '[:alnum:][:punct:]'.

last updated: