UNIX File Permissions Tutorial
UNIX File Permissions Tutorial
html
Every user on a Unix system has a unique username, and is a member of at least one group (the primary group
for that user). This group information is held in the password file (/etc/passwd). A user can also be a member
of one or more other groups. The auxiliary group information is held in the file /etc/group. Only the
administrator can create new groups or add/delete group members (one of the shortcomings of the system).
Every directory and file on the system has an owner, and also an associated group. It also has a set of
permission flags which specify separate read, write and execute permissions for the 'user' (owner), 'group', and
'other' (everyone else with an account on the computer) The 'ls' command shows the permissions and group
associated with files when used with the -l option. On some systems (e.g. Coos), the '-g' option is also needed
to see the group information.
Understanding how to read this output is useful to all unix users, but especially people using group access
permissions.
On an executable program with set-UID or set-groupID, that program runs with the effective permissions of
1 of 4 6/9/2013 1:02 PM
UNIX File Permissions Tutorial http://www.dartmouth.edu/~rc/help/faq/permissions.html
For a directory, the set-groupID flag means that all files created inside that directory will inherit
the group of the directory. Without this flag, a file takes on the primary group of the user creating
the file. This property is important to people trying to maintain a directory as group accessible. The
subdirectories also inherit the set-groupID property.
Typically the default configuration is equivalent to typing 'umask 22' which produces permissions of:
-rw-r--r-- for regular files, or
drwxr-xr-x for directories.
In other words, user has full access, everyone else (group and other) has read access to files, lookup access to
directories.
When working with group-access files and directories, it is common to use 'umask 2' which produces
permissions of:
-rw-rw-r-- for regular files, or
drwxrwxr-x for directories.
The command to change the permission flags is "chmod". Only the owner of a file can change its permissions.
The command to change the group of a file is "chgrp". Only the owner of a file can change its group, and can
only change it to a group of which he is a member.
See the online manual pages for details of these commands on any particular system (e.g. "man chmod").
2 of 4 6/9/2013 1:02 PM
UNIX File Permissions Tutorial http://www.dartmouth.edu/~rc/help/faq/permissions.html
chmod -R g+rw .
give group read write access to this directory, and everything inside of it (-R = recursive)
chgrp -R medi .
change the ownership of this directory to group 'medi' and everything inside of it (-R = recursive). The
person issuing this command must own all the files or it will fail.
WARNINGS:
Putting 'umask 2' into a startup file (.login or .cshrc) will make these settings apply to everything you do
unless manually changed. This can lead to giving group access to files such as saved email in your home
directory, which is generally not desireable.
Making a file group read/write without checking what its group is can lead to accidentally giving access to
almost everyone on the system. Normally all users are members of some default group such as "users", as well
as being members of specific project-oriented groups. Don't give group access to "users" when you intended
some other group.
Remember that to read a file, you need execute access to the directory it is in AND read access to the file
itself. To write a file, your need execute access to the directory AND write access to the file. To create new
files or delete files, you need write access to the directory. You also need execute access to all parent
directories back to the root. Group access will break if a parent directory is made completely private.
For details see the man pages for: fs_setacl, fs_listacl, fs_cleanacl, fs_copyacl
The default is to give the same permissions to a new directory as are on the parent directory. In practice, this
is usually to give complete rights to the owner of the directory, and lookup rights to any other user (equivalent
to execute attribute on a directory).
- replace DIRNAME with the appropriate directory name (or "." for the current directory, and MYNAME
with your login name.
Check it with:
3 of 4 6/9/2013 1:02 PM
UNIX File Permissions Tutorial http://www.dartmouth.edu/~rc/help/faq/permissions.html
fs listacl DIRNAME
(see man fs_setacl for a description of the meaning of the flags "rlidwka")
If "fs" is not found, or the man pages are not found, your paths are not set up correctly. I recommend you run
/usr/local/bin/mknewdotfiles to correct that.
4 of 4 6/9/2013 1:02 PM