To generate strong passwords in Linux or UNIX systems using the /dev/urandom
device, you can use the tr
command to translate random bytes into printable characters.
Here’s an example command that generates a random 12-character password using /dev/urandom
:
tr -dc A-Za-z0-9 < /dev/urandom | head -c 12 ; echo ''
This command uses tr
to delete (-d) any characters that are not alphanumeric (A-Z, a-z, 0-9), and then uses head
to limit the output to 12 characters. The echo
command is used to add a newline character at the end of the output.
You can adjust the length of the password by changing the argument to head
to a different value.
You can also make the password more secure by adding special characters to the character set used by tr
. For example, to include special characters in the password, you can modify the command like this:
tr -dc A-Za-z0-9\_\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 16 ; echo ''
This adds the characters _
, @
, #
, $
, %
, ^
, &
, *
, (
, )
, -
, +
, and =
to the character set used by tr
, and generates a 16-character password.
Note that the tr
command generates passwords that are completely random, which can be difficult to remember. It is recommended to use a password manager to securely store and manage passwords, rather than relying on memory.