How to Generate Secure Passwords for your Linux Servers Print

  • Linux, server, passwords, generator
  • 2

Generating secure passwords

For selecting secure passwords, here’s what is recommended:

  • Passwords should be at LEAST 10 16 characters in length.
  • Include letters (mixed case), numbers and special characters.

Using pwgen to generate secure password

Here’s my go-to command line method for secure password generation. The command I use is:

pwgen -y 32

Even more secure:

pwgen -ys 32

-y, –symbols Include at least one special character in the password. -s, –secure Generate completely random, hard-to-memorize passwords. These should only be used for machine passwords, since otherwise it’s almost guaranteed that users will simply write the password on a piece of paper taped to the monitor…
32 the length of generated passwords. Need fewer generated passwords? Use pwgen -ys 32 1 where 1 = the number of password results.

More about pwgen here. On most Linux distros you can install pwgen using the package manager. For example:

Use the urandom command to generate secure passwords


Recommended urandom

< /dev/urandom tr -dc '[:graph:]' | head -c16;echo;

Right-hand only urandom

< /dev/urandom tr -dc '67890^*_+-=;:,.?yuiopYUIOPhjklHJKLbnmBNM' | head -c16;echo;

Left-hand only urandom

< /dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c16;echo;

Make this into a simple easy to remember command
Edit your bashrc

vi ~/.bashrc

Add this line:

spwd(){ < /dev/urandom tr -dc '[:graph:]' | head -c16;echo; }

Save and restart server or even better just reload bash using:

source ~/.bash_profile

Now in future just type the following to generate a secure password:

spwd

Was this answer helpful?

« Back

<-- removed to be added again -->