Random number generation

The Linux kernel supplies a random number generator which is accessed through /dev/random and /dev/urandom. Programs that utilize the random and urandom devices, such as OpenSSH, will benefit from these instructions.

When a Linux system starts up without much operator interaction, the entropy pool, data used to compute a random number, may be in a fairly predictable state. This creates the real possibility that the number generated at startup may always be the same. In order to counteract this effect, you should carry the entropy pool information across your shut-downs and start-ups. The following init.d script and links will perform this function for you automatically.

cat > /etc/rc.d/init.d/random << "EOF"

# Begin $rc_base/init.d/random

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org
# Random script elements by Larry Lawrence

source /etc/sysconfig/rc
source $rc_functions

case "$1" in
                echo "Initializing kernel random number generator..."
                if [ -f /var/tmp/random-seed ]; then
	                cat /var/tmp/random-seed >/dev/urandom
		dd if=/dev/urandom of=/var/tmp/random-seed count=1 &>/dev/null
		echo "Saving random seed..."
		dd if=/dev/urandom of=/var/tmp/random-seed count=1 &>/dev/null

                echo "Usage: $0 {start|stop}"
                exit 1

# End $rc_base/init.d/random
chmod 755 /etc/rc.d/init.d/random

Create the symbolic links to this file in the relevant rc.d directories with the following commands:
cd /etc/rc.d/init.d &&
ln -sf ../init.d/random ../rc0.d/K45random &&
ln -sf ../init.d/random ../rc2.d/S25random &&
ln -sf ../init.d/random ../rc3.d/S25random &&
ln -sf ../init.d/random ../rc4.d/S25random &&
ln -sf ../init.d/random ../rc5.d/S25random &&
ln -sf ../init.d/random ../rc6.d/K45random