If you ran the following, what would happen?
# Do not run.
# cat /dev/random > ~/randomFile
Would it be written until the drive runs out of space, or would the system see a problem with this and stop it (like with an infinite symlink loop)?
If you ran the following, what would happen?
# Do not run.
# cat /dev/random > ~/randomFile
Would it be written until the drive runs out of space, or would the system see a problem with this and stop it (like with an infinite symlink loop)?
It writes until the disk is full (usually there is still some space reserved for the root user). But as the pool of random data is limited, this could take a while.
If you need a certain amount of random data, use dd.
For 1MB:
dd if=/dev/random iflag=fullblock of=$HOME/randomFile bs=1M count=1
Other possibilities are mentioned in answers to a related question.
However, in almost all cases it is better to use /dev/urandom instead.
It does not block if the kernel thinks that it get out of entropy.
For better understanding, you can also read myths about /dev/urandom.
Installing haveged speeds up /dev/random and also provides more entropy to /dev/urandom.
EDIT: dd needs the fullblock option as /dev/random (in opposite of /dev/urandom) can return incomplete blocks if the entropy pool is empty.
If your dd does not support units, write them out:
dd if=/dev/random iflag=fullblock of=$HOME/randomFile bs=1048576 count=1
/dev/urandom is fine, there's no reason not to do it. And do not use a Mersenne twister to do crypto. And don't use /dev/random on Linux.
– Gilles 'SO- stop being evil'
Feb 05 '13 at 21:46
/dev/urandom is fine for cryptographic use. Do not use /dev/random.
– Thomas Pornin
Feb 05 '13 at 22:12
iflag=fullblock is needed. Answer is updated.
– jofel
Feb 06 '13 at 13:42
head -c 123 /dev/urandom to read a given amount of data from a device. I'd expect this to be less affected by the incomplete block scenario. Might be less performant, though.
– MvG
Feb 15 '13 at 20:32