11 ms·
Need some random data quickly? dd if=/dev/urandom count=1024 bs=1 | base64 Need it to be in a particular subset of characters? dd if=/dev/urandom count=1024
by cratermoon 4y ago
Need some random data quickly?
dd if=/dev/urandom count=1024 bs=1 | base64
Need it to be in a particular subset of characters?
dd if=/dev/urandom count=1024 bs=1 |tr -dc 'A-Za-z0-9'
Note: if you're on a mac, its tr is kind of broken. Do export LC_ALL=C first.
- morepork 4y agoI find head easier for these, replace the first part of your commands with head -c 1024 < /dev/urandom
- btdmaster 4y agoThe shell redirection < can be removed too, since head supports specifying files [from manual page HEAD(1)]: head [OPTION]... [FILE]...
- cratermoon 4y agoThat just prints a bunch of garbage characters for me. I tested it on mac and Ubuntu xenial. Maybe it works differently elsewhere.
- morepork 4y agoYou still need to pipe through base64, i.e. head -c 1024 /dev/urandom | base64
- 0xbadcafebee 4y agoYou can specify LC_ALL= on the same line, right before tr. Here's another example of a password generator (without dd): LC_ALL=C tr -dc 'a-zA-Z0-9-_\$' </dev/urandom | fold -w 20 | sed 1q