Having a strong password is the most important thing you can do to protect your account or server and to keep your data secure. Common thinking is that a strong password should be comprised of at least 14 characters, including lowercase and uppercase alphabetic characters, numbers, and symbols and should never be based on a dictionary word. Using a long password is much more secure than using a short one, the longer the password the harder it is to guess. In this post, we will take a look at several different ways to generate a strong password using the Linux command line.
With openssl
This method uses the openssl rand function and it will generate 14 characters random string:
openssl rand -base64 14
With urandom
In this method we will filter the /dev/urandom output with tr to delete unwanted characters and print the first 14 characters:
< /dev/urandom tr -dc A-Za-z0-9 | head -c14; echo
With gpg
We can also use the gpg tool to generate a strong 14 characters password:
gpg --gen-random --armor 1 14
With strings
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 14 | tr -d '\n'; echo