

The pwgen utility is a small command line program that generates passwords. This command also doesn't print a new line, use the xargs trick above if needed. $ strings /dev/urandom | tr -d '\n' | head -c18 Here we use it to pull printable characters for urandom, then use tr to strip the new lines, and head to print the first 18.

The strings command is not one of those commands that is used very often. $ openssl rand -base64 16 | cut -c-18į+0iF8Rmc9V1/fnmiQ Using the strings Command To get our 18 character length we can change to 32 (or 16) and cut the first 18 characters. For example, I can't do 18 (which I like). Because of the base64 encoding, there are some lengths you cannot select. I am not a fan of this one, but maybe you are. This one gives us a nice clean output with a new line. Here is an example that does the same thing as the first example using redirection to input the file instead of cat. If you wanted a password without special characters, you can change the tr command to: If you wanted a shorter, or longer password you can change the number in the head command. $ cat /dev/urandom | tr -cd '' | head -c 18 Then the head command is telling the command to print the first 18 characters and then stop. The tr command is then stripping out all printable characters, not including spaces. Here we are reading the urandom file with cat and piping it to tr. $ cat /proc/sys/kernel/random/entropy_avail This will be a number in the range of 0-4096. You can check the available entropy on most Linux systems by reading the /proc/sys/kernel/random/entropy_available file. From this entropy pool random numbers are created.
COMMAND LINE PASSWORD MINI SIZE GENERATOR
The generator also keeps an estimate of the number of bits of noise in the entropy pool.
COMMAND LINE PASSWORD MINI SIZE DRIVERS
The random number generator gathers environmental noise from device drivers and other sources into an entropy pool. The character special files /dev/random and /dev/urandom (present since Linux 1.3.30) provide an interface to the kernel's random number generator. Most of these example use the urandom file in dev.

In this Linux quick tip, we will show you 5 bash commands (plus one utility) to quickly generate a random password. So why not use the command line to generate random passwords? I use still use lynx (a command line browser), dict (a command line dictionary), and bc (a command line calculator) although with decreasing regularity. If it was up to me I would never leave the command line.
