How do I create temporary files and directories using /dev/urandom on linux?



  • Also see: Man page for urandom

    If you need to be extra careful and secure about what to name your temporary file names. This can be used.

    Important: Do not just cat the file /dev/urandom on its own, the file is a pseudodevice. It could terminate your shell session or lock it.

    $ touch /tmp/secure_file.$(cat /dev/urandom | od -x | tr -d ' ' | head -n 1)
    

    The od -x create an octal dump, tr -d removes spaces, head -n 1 grabs the first line of the octal dump.

    The result is:

    $ ls /tmp/secure_file*
    -rw-rw-r-- 1 trainer trainer 0 Nov 13 11:45 secure_file.00000004e6a05447ce5151877e268374b6d5df4
    

    The name is hard to guess but, you may want to make the permissions 600 as well


Log in to reply
 

© Lightnetics 2020