Linux - generate random password using /dev/urandom


Today we will look at, in our opinion, one of the most convenient ways to generate a password on your Linux server using /dev/urandom.


What is /dev/urandom in Linux?


generate random password in Linux

First, let's look at what urandom is. The urandom command is used to generate a random password, including one-time and long-term passwords. /dev/urandom uses an entropy pool it will generate data using SHA, MD5 or any other algorithm. /dev/urandom is the preferred random number generator for cryptographic tasks on UNIX-like systems over /dev/random. Please note that this command can be used not only for Linux/Unix, but also for MacOS.


Command for random generated password using /dev/urandom:


tr -dc A-Za-z0-9 < /dev/urandom | head -c 8 | xargs


Password example:
4fFUND1d


The command - tr filters output from /dev/urandom such that it will get your password from A to Z, a to z and 0 to 9.

The command - head will generate a string of 8 characters.


Summing Up


In this article, we explained what /dev/urandom is, and also showed a command that allows you to generate a random password. /dev/urandom is considered reliable and errors when using it are unlikely.