How to generate strong passwords in the Linux Terminal?

We all know that strong passwords are important for better security, and you should have a unique and long alphanumeric password for every website. Now, you can of course use an open-source password manager such as KeePassXC, but what if I tell you that you can generate passwords directly without installing any GUI application?

Well, note that this method is not 100% effective as you will have to use another application to store that complicated alphanumeric password (Please do not use your Notebook to store passwords).

Method 1: Generating strong passwords with pwgen

Pwgen, as the name suggests, is a simple command line utility to generate passwords. It is available on almost every distribution’s package manager and can be easily installed on your system. Just run the following command in your Terminal:

# On Debian and Ubuntu based distributions
sudo apt update && sudo apt install pwgen

# On Arch based distributions
sudo pacman -S pwgen

# On Fedora Workstation
sudo dnf install pwgen
Installing Pwgen On Fedora
Installing Pwgen On Fedora

Now that you have installed pwgen, you can generate a let’s say 10 digit password by typing the following command :

pwgen 10 1
Generating A Password Using Pwgen
Generating A Password Using Pwgen

Here, ‘1’ tells the command that we only need one password. If you do not use ‘1’, then by default, it gives you 100 passwords simultaneously.

Generating hundreds of strong Passwords Using The Pwgen Command
Generating a hundred passwords using the Pwgen command

You can of course use more options along with the command, such as -v (no vowels), -y (for symbols), etc. You can read more about them on the manual page of this command.

Method 2: Generating strong passwords using OpenSSL

OpenSSL is pretty much a full-featured, commercial-grade toolkit utilized for cryptography purposes. We can also use this tool to generate strong passwords on Linux-based systems, as it ships mostly with all Linux systems by default. Just open a Terminal and type the following command :

openssl rand -base64 10
Generating Passwords Using OpenSSL
Generating Passwords Using OpenSSL

Here, the ‘-base64’ option tells the OpenSSL command to make sure that the output can be typed on a Keyboard. I’ve also specified the byte size, which is 10 here.

You should also check the manual page of OpenSSL and base64 commands to know more about them and their use cases.

Method 3: Generating strong passwords with GPG

GPG or GNU Privacy Guard is yet another encryption program that is shipped along with every Linux distribution. You just need to run the following commands to generate a strong password using GPG :

gpg --gen-random --armor 1 10
Generating Password Using GPG
Generating Password Using GPG

This has generated a 10-digit alphanumeric password, however, you can generate passwords of any length using this command.

Method 4: Hash anything

Think of any random word, place, or animal, and then just pass it through a checksum such as md5sum or sha256. Here, I have passed today’s date through this command :

date | sha256sum
Generating Passwords Using Checksum
Generating Passwords Using Checksum

Similarly, using the md5 checksum, you can generate strong passwords :

echo "LinuxForDevices" | md5sum
Generating Random Password With Md5sum
Generating Random Password With Md5sum

Summary

You should always use alphanumeric strong passwords, although they are a bit hard to remember, they are hard to crack as well by any malicious application or by a hacker brute forcing your system.

And as mentioned earlier in this article, keeping your strong passwords in an unsecured place such as a notebook is not recommended. Use a password manager. Also, make sure that you clear your bash_history file if you have decided on a password to use on some websites. If you have any questions regarding this tutorial, please go ahead and ask in the comments.

References

Sha256sum Manual Page

OpenSSL Manual Page

pwgen Manual Page