/dev/random and /dev/urandom are special character files present since Linux kernel version 1.3.30.
They provide an interface to Kernel’s Random Number Generator.
The Random Number Generator gathers environmental noise from device drivers and other sources into entropy pool. It also keeps an estimate of Number of bits of noise in entropy pool. It is from this entropy pool, random numbers are generated
It will only return Random bytes from entropy pool. If entropy pool is empty, reads to /dev/random will be blocked until additional environmental noise is gathered. This is suited to high quality randomness, such as one-time pad or key generation.
TIP: Issue the command ‘cat /dev/random’ into your terminal without quotes. Move the mouse or type anything on the keyboard to see random characters being generated. Press CTRL+C to exit the situation.
It will return as many random bytes as requested. But if the entropy pool is empty, it will generate data using SHA, MD5 or any other algorithm. It never blocks the operation. Due to this, the values are vulnerable to theoretical cryptographic attack, though no known methods exist.
TIP: Issue the command ‘cat /dev/urandom’ into your terminal without quotes. Sit and watch random characters being generated, while you do nothing. Press CTRL+C to exit the situation.
Creating /dev/random & /dev/urandom, if your System doesn’t have them
Minor Device number of /dev/random – 1
Major Device number of /dev/random – 8
Minor Device number of /dev/urandom – 1
Major Device number of /dev/urandom – 9
STEP1: Creating character file with mode/permission as 644
# mknod -m 644 /dev/random 1 8
STEP2: Creating character file with mode/permission as 644
# mknod -m 644 /dev/urandom 1 9
STEP3: Changing ownership & group of created devices to ‘root’
# chown root:root /dev/random /dev/urandom
NOTE: These changes doesn’t persist across a reboot