Creating files with the correct permission on *nix

If you need to create files in *nix, even temporary ones you probably want to make sure that they have the correct permissions. Most default installs actually setup pretty permissive permissions for default permissions so if you create a file and then chmod it there will be a window of opportunity for a hacker to read it.

Instead you need to create the file with the write permission in the first place. Use the umask function to do that. There’s normally an implementation of that in whatever language you need. It’s even available on the shell. C and Perl have theirs too.