Real Clear Computing

Generate Random Passwords in Linux

Using the openssl Command

openssl rand -base64 12

This generates a 16-character password with Base64 encoding. Note that the last number, 12, represents the number of bytes, not the password length. The openssl command generates 4 characters for every 3 bytes.

Using the pwgen Command

The following command generates one 16-character password:

pwgen 16 1

The following command generates two 16-character password and include uppercase letters, numbers and symbols:

pwgen 16 2 -cny

Options

Install Pwgen if it’s Not Already Installed

Install pwgen for Debian/Ubuntu-based distros:

sudo apt install pwgen

Install pwgen for RHEL/CentOS-based:

sudo dnf install pwgen