There are a lot of ways to generate random passwords, starting from simple password generator sites found online to the most advanced password management solutions. Today’s topic will be focused on creating passwords from the CLI using quick and simple methods.
- Shell environment
Let’s start with the good old
$ openssl rand -base64 16
Alternatively, gpg or known as GnuPG is a command-line cryptographic tool and I highly recommend it.
$ gpg --gen-random --armor 1 16
Last but not least,
/dev/urandom is known as a pseudorandom number generator.
$ tr -dc A-Za-z0-9 < /dev/urandom | head -c16; echo
- If you are getting
tr: Illegal byte sequenceerror, add
LC_CTYPE=Cin front of the command:
LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom | head -c16; echo
- If you want to add special characters as well, your command should something like:
$ LC_CTYPE=C tr -dc 'A-Za-z0-9_!@#$%^&*()\-+=' < /dev/urandom | head -c16; echo
Now, I’ve seen using the system date (
date command) as an alternate method, but this is really bad, since it’s basically a weak strategy and a predicable one too. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on telegram.