3 fast ways to generate a random password from the command line in Linux

First up, if you really want to generate random passwords, I say scrap the command line and use LastPass to generate a random password.  It lets you set the password length, case, symbols, minimum digit counts and a bunch of other things. It’s actually the fastest way to generate a random password other than by making love to your wife on your keyboard with notepad open and recording the gibberish that comes out.

Graphic but true.  Let’s get on with it lol.

I’m going to move quick here so catch me if you can.

1. Get a date

Need a rando password like right now?  Why the hurry?

Okay, that’s none of my business.

The bottom line is if you need a quick one just type:

date | md5sum

Use date | md5sum to generate a random password

So what’s going on here?

We’re just running the data output of the date command into a 128 cryptographic md5 checksum function.  Despite the convoluted explanation, it’s not the most secure thing in the world.  The bottom line is that it exceeds most password length requirements and is relatively random since it’s based on the ever changing time input.

2 U so random!

the /dev/urandom application gives us a little more precision than the md5sum thingy we typed earlier.  Here’s the command :

sudo < /dev/urandom tr -dc _A-Z-a-z-0- | head -c12

Using urandom to generate a rando password

Yes, the output is a little confusing because the command is long and the output is poorly formatted.

In the above screenshot, the password is highlighted immediately to the left of the second line.

That last part of the command head -c12 specifies the character length – so if you wanted 15 characters instead of 12 you would change it to:

head -c15

3. Duplicate me baby

The dd command is usually used to copy and convert files.  Today we’re gonna make it do something it never dreamed of: generate random passwords.

Oh yeah! lol

dd if=/dev/urandom bs=1 count=16 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev

Using dd to generate random passwords

And now we have a 16 character super random password that would importune even the most resolute hackers.

Pew!

That’s it.  In the blink of an eye we have three methods of generating random passwords in Linux.

If you have any other methods please share in the comments!

About

Connect with Vonnie on Twitter

Posted in Linux, Mac OS X 10.10 Yosemite, Mac OS X 10.8 Mountain Lion, Mac OS X 10.9 Mavericks Tagged with: ,