Secure /tmp usage for bash scripting

I’ll cut to the chase…

# Secure tmp directory usage.
tmp=${TMPDIR-/tmp}
tmp=$tmp/unf.$RANDOM.$RANDOM.$RANDOM.$$
(umask 077 && mkdir $tmp) || {
echo “Could not create temporary directory! Exiting.” 1>&2
exit 1
}
(umask 077 && mkdir $tmp/mebad) || {
echo “Could not create temporary directory! Exiting.” 1>&2
exit 1
}

2 Comments to “Secure /tmp usage for bash scripting”

  1. Kenny Root Says:

    I think you mean “/bin/mktemp”

  2. Paul Says:

    You’re right. I do. Thanks for the tip.

Comment:

RSS subscribe

For spam filtering purposes, please copy the number 2353 to the field below: