default read permisions for users

Is something that have me thinking for a long time...the question is, why a normal user can read the files on root folder?
or even files like rc.conf loader.conf , etc
is there a way to change the permisions for that files only to read/write to root?
 
Well after installation I just do
chmod 700 /root
chmod 700 /usr/home/myuser
Permissions in /etc and /usr/local/etc are far more complicated . I don't know if the defaults are always the best.
 
The /root directory is just the home directory of the user whose name is root. There is nothing wrong with using a directory other than /root for that user (except for problems with logging in when file systems don't mount, or with running in single-user mode). So your first question should be phrased: Why are files in the home directory of user root readable by everyone else?

Answer: This is not specific to root, but applies to all users. For the last ~50 years, the tradition in Unix has been that the default is that files of any user are also readable by all other users. The default umask has always been 022 or 002. There are specific exceptions, for example by default user's mail directories are set to be unreadable by other users, or the users .ssh directory and private keys are not only unreadable, they will be ignored if writable by others; those exceptions are enshrined in various programs and scripts that create and use those more protected files and directories.

If you want, you can change these defaults, and you can change user's directories to not be readable by others. That really depends on the environment and uses of the system. For example, in a corporate setting for an engineering system it makes perfect sense that the default should be that files from one user (including the user called root) should be readable by all other users, since they are all used for work-related tasks, and they are all employees of the same company, sould there should be no expectation of privacy. For a system with multiple personal (non-professional) users, like an ISP catering to individuals, the default should be that directories are non-readable.

Now to your second question: Why are files in /etc/ (and by extension in /boot and in /usr/local/etc and so on) readable by anyone? Because they don't contain secrets. Looking at /etc/rc.conf doesn't tell you anything you couldn't deduced by normal use of the system, and files like /etc/services are completely standard on all systems. Matter-of-fact, many files in those areas absolutely need to be readable by users; for example, if you protect /etc/passwd, /etc/profile and /etc/shells against users, many things relating to the simple task of logging in will stop working.

The deeper underlying question you didn't ask is this. What do you expect to gain by making these files unreadable? If you think it will make the system more secure, you are mostly wrong: security through obscurity doesn't work in this case, because a regular user can mostly figure out what the content of these files is (for example by downloading a FreeBSD install kit and looking). You might be asking: why doesn't Unix have more strict separation between users, where one user can't even see the existence of other users? Because that was not part of its requirements, and therefore is not part of its design.
 
Last edited:
Back
Top