Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Where are default permissions for files and directories set before a umask is applied to limit those?

Or are they 0777 by default?

share|improve this question
AFAIK they're set to 777 for directories and 666 for files, not sure where this default comes from though. – Thor Sep 18 '12 at 9:16
up vote 1 down vote accepted

AFAIK it's hard-coded (in some sense) into every program that can create files.  I basically agree with @Thor: it's typically 777 for directories and executable files (i.e., compilers use 777), and 666 for all others (data files, named pipes, "special" (device) files, etc.)  The default mode for file-system sockets would probably have to be hard-coded in the kernel, since AFAIK the bind system call doesn't allow the program to specify that.

I said "in some sense" because many programs use library functions (e.g., fopen in the stdio package) to do file I/O, so in their case the default mode is hard-coded in the library function.

That said, it's possible that some versions of *nix have a configuration file somewhere, and some or all programs and library functions read this configuration file to get the default mode.

share|improve this answer
so no .h files that would define access rights? wouldn't the permission system have to have such? – Gung Foo Sep 18 '12 at 16:11
@Gung Foo: I'm not sure what you're asking. <sys/stat.h> defines constants like S_IRUSR = 0400 and S_IWGRP = 0020, but these are for the benefit of programs that want to use the stat system function to get a file's mode and interpret it. Yes, the kernel code uses this .h file (or an equivalent one) also, but that wouldn't have to be on an operational system unless it had the kernel source code and was being used as a kernel code development/build/test system. And, yes, it's possible that some programs get their default mode from a .h file -- that's just a form of hard-coding. – Scott Sep 18 '12 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .