DEV Community

Cover image for Generate passwords from CLI
Alberto Gonzalez Escalante
Alberto Gonzalez Escalante

Posted on Edited on

Generate passwords from CLI

Problem

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

Solution

Use the command below:

LC_ALL=C </dev/urandom tr -cd '[:alnum:]' | head -c 32
Enter fullscreen mode Exit fullscreen mode

Explanation

This command 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 replacing the character class with [:graph:] as in tr -cd '[:graph:]'.

Top comments (0)