How to Generate Strong, Unique Passwords on Linux
Today we will learn how to generate strong random passwords using the Linux command line. While there are several tools available for this, we’ll focus on two: openssl
(installed by default) and pwgen
.
How to generate Passwords using Pwgen
The pwgen
command is a very user-friendly tool for generating passwords. However, you’ll need to install it first.
To install pwgen on Debian/Ubuntu-based distros, run the following command:
sudo apt install pwgen
To install pwgen
on RHEL/CentOS and Fedora, run the following command:
sudo dnf install pwgen
To generate passwords, use the following command syntax:
pwgen <length> <num of passwords>
For example, to generate one 8 character password run the following command:
pwgen 8 1
Include Uppercase Letters, Numbers, and Symbols for Added Security
There are couple of command options for make passwords strong with pwgen
:
-c
: Include at least one uppercase letter.-n
: Include at least one number.-y
: Include symbols.
Here is a example of generating 32 character passwords that includes uppercase letters, numbers and symbols:
pwgen 32 1 -cny
How to generate a Password using OpenSSL
OpenSSL
is installed by default on most Linux systems. Here is a example of generating a password using OpenSSL
command:
openssl rand -base64 6
In the previous command, number 6 represents the number of bytes. However, the number of bytes is not the same as the length of the password. What happens is that openssl
generates 4 characters for every 3 bytes.
For example, if you specify a number between 1 and 3, it will generate a password with 4 characters. If you specify a number between 4 and 6, it will generate a password with 8 characters.
And that brings us to the end of this tutorial on generating passwords in the Linux command line. If you found this helpful, don’t forget to subscribe to our YouTube channel, @RealClearComputing, for more Linux tutorials and tips.