## 49.7. Add Users to a Group to Deny Permissions

Usually, Unix group access allows a group of users to access a directory or file that they couldn't otherwise access. You can turn this around, though, with groups that deny permission.

This trick works only on Unix systems, like BSD (FreeBSD, Darwin, OpenBSD, and so on), that let a user belong to more than one group at the same time.

For example, you might work on a computer that has some proprietary files and software that "guest" accounts shouldn't be able to use. Everyone else on the computer should have access. To do this, put the software in a directory owned by a group named something like deny. Then use chmod to deny permission to that group:

>     # chmod 705 /usr/local/somedir
>     # ls -lgd /usr/local/somedir
>     drwx---r-x  2     root   deny      512  Mar 26 12:14 /usr/local/somedir

Finally, add the guest accounts to the deny group.

Unix checks permissions in the order user-group-other. The first applicable permission is the one used, even if it denies permission rather than grant it. In this case, none of the guest accounts are root (we hope!).

They're members of the group called deny, however; that permission (`---`) is checked and the group members are shut out. Other users who aren't members of deny are checked for "other" access (`r-x`); they can get into the directory.

The same setup works for individual files (like programs). Just be careful about changing system programs that are SUID or SGID.

-- JIK

Copyright © 2003 O'Reilly & Associates. All rights reserved.