How to generate a password in Shell on Linux?

Posted on In QA, Tutorial

Admins usually need to generate some passwords for others, such as when creating a new user in a Linux system. How to generate a password in Shell on Linux?

Several possible and short methods. Here, we generate a password of length 8.

Using pwgen:

$ pwgen 8 1
dao3PaW9

Password based on base64 (note that the encoding of a 6 char string will be 8 chars in base64) with random numbers generated from various ways.

Using gpg:

$ gpg --gen-random -armor 1 6
eXDvMVq2

Using openssl:

$ openssl rand -base64 6
1E8oiu5G

Using Linux’ /dev/urandom:

$  head -c 6 /dev/urandom | base64
Ilna5Pj8

There are possibly more.

Leave a Reply

Your email address will not be published. Required fields are marked *