How to Generate Strong Linux Passwords and Verify Their Strength

This tutorial explains how to create complex, high‑entropy passwords on Linux using GPG or OpenSSL, optionally filter out special characters with sed, and then assess password strength with the cracklib‑check tool on CentOS 8, illustrating both weak and strong examples.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Generate Strong Linux Passwords and Verify Their Strength

Strong passwords should combine letters, numbers, and symbols while avoiding known words, birth dates, or personal names to resist dictionary attacks. Although there is no strict length rule, passwords longer than 16 characters are generally recommended.

On a Linux system with gpg installed, you can generate a random password using the --gen-random and --armor options. For example:

[root@localhost ~]# gpg --gen-random --armor 2 12
zXVKRoB0/V4BN9QG

If you prefer a password without special characters, pipe the output through sed to remove anything that is not a letter or digit:

[root@localhost ~]# gpg --gen-random --armor 2 12 | sed 's/[^a-zA-Z0-9]//g'
n4ciIlRLkLTkzwg

The same approach works with openssl. Generate a base‑64 string and optionally filter it:

[root@localhost ~]# openssl rand -base64 12
QIrH/PLXqzmLuI/a
[root@localhost ~]# openssl rand -base64 12 | sed 's/[^a-zA-Z0-9]//g'
lXIg4cKLCLVvsi

To evaluate password strength, install the cracklib utility on CentOS 8: [root@localhost ~]# yum -y install cracklib Testing a simple dictionary‑based password shows it is rejected:

[root@localhost ~]# echo "a1b2c5" | cracklib-check
a1b2c5: it is based on a dictionary word

Another example with a common word also fails:

[root@localhost ~]# echo "Administrator" | cracklib-check
Administrator: it is based on a dictionary word

Finally, test a generated password; the tool reports it as acceptable:

[root@localhost ~]# openssl rand -base64 12 | cracklib-check
VdBlmvIgGY4ehWly: OK

These commands demonstrate how to produce high‑entropy passwords and verify that they meet basic security criteria using standard Linux tools.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SecurityOpenSSLpassword generationGPGcracklib
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.