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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s