Linux Secure Password Generation: 4 Easy Methods

Quick Linux Tip #107:

Question: I need to generate secure passwords without using a website.

Try: openssl rand -base64 32 | tr -d '/+=' | cut -c1-20

Info: Generates cryptographically secure random bytes from OpenSSL.

Examples:

  • $ pwgen -s 20  # Generate fully random 20-character passwords
  • $ head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20  # Pure bash random string generation
  • $ openssl rand -hex 16  # Generate a 32-character hex string

Note: Modern Linux kernel entropy (/dev/urandom) is cryptographically secure. Avoid using $RANDOM for passwords as pseudo-random generators are predictable.




LinuxTeck.com
linuxteck:~$ openssl rand -base64 32 | tr -d '/+=' | cut -c1-20
7Kj9mLqN3Vxp2Rt8sAyW

linuxteck:~$ openssl rand -base64 48 | head -c 32; echo
4Rn7Xp2Lq9mK3jVt8wA5bYz6NsHcF1gD

linuxteck:~$ pwgen -s 20 5
K7jN9mLq3VxN2Rt8sAyW
4Rn7Xp2Lq9mK3jVt8wA5
8bYz6NsHcF1gD5tP9rJm
M3kL7qN2VxP4Rt8sAy9W
6Rn9Xp3Lq4mK7jVt2wA8

linuxteck:~$ head -c 16 /dev/urandom | base64
L+r2V8NxQmP5kA7F9Rbw/A==
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #106: Linux RAM Filesystem: 4 Steps to Speed Up Builds NEXT ARTICLE Quick Linux Tip #108: Linux Log Compression: 4 Steps to Save Disk Space
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.