Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help >  Unix

Unix groups and file permissions

Contents
The early part of this document is for users wanting to know more about permissions and groups. Later on there's information aimed more at teaching staff and administrators

Introduction

In Unix, a user's access to files is determined by the permissions set on the file and its parent folders, and the identity of the user. Each user has an identifier (a login name - type whoami to find yours). Also, each user belongs to one or more groups (type groups to see which groups you belong to) but is only in one group at a time. Typing id displays all the identification information about the user - the gid entry shows the user's current group.

When a user creates a file, it is owned by the user and belongs to the user's current group. Try

  touch cabbage
  ls -l cabbage

to create a file and display details about the file. You'll see that there are many details. For now just check that column 3 shows who owns the file and column 4 shows what group owns the file.

Permissions

Files are not simply readable or non-readable - independent read/write/execute controls can be set for the file-owner, the people belonging to the file's group, and all other users. This information is shown in the 1st column of ls -l's output. If you type
  ls -l /etc/passwd
you'll get something like
-rw-r--r--  1 root  root   175939 May 10 00:22 /etc/passwd
The graphical interface (shown right) also lets you see the permission in this traditional way if you select the right option
permissions
The first column of this output consists of 10 characters. The first shows what sort of file it is - a directory (in which case the character which be 'd'), a plain file (as here, the character being '-'), etc. The other 9 characters form 3 triplets. The first triplet shows read, write, and execute permissions for the owner of the file. The other 2 triplets show what permissions fellow group members and others have. The easiest way to interpret and change these permissions is to make use of a graphical (rather than command line) interface to Unix.
permissions If you click with the right mouse-button on a file and select the Properties menu option, then the Permissions tab, you'll see something like the panel in the left, which has buttons to selectively control access for different categories of user. If you click in the same way on a folder, you'll get a panel more like the one on the right. The execute permission is interpreted differently for folders, as described in the next section. permissions

Directories/Folders

What do the rwx permissions mean for directories? A directory is just a list of entries, so
directory tree diagram In this situation,
  • the owner (tpl) can read all the files
  • people in group divf can do "ls dir1" to list the files in the directory. They can read file1 and file2 but not file3
  • other users will get an "unreadable" message if they try "ls dir1" but if they type "more dir1/file1" they'll be able to read the file. They won't be able to read file2 or file3
Note that it's not the ownership of the file that determines whether a user can remove it, but the writability of the directory that the file's in.

Changing the permissions of a file

Only the owner of a file (or the system administrator) can change permissions. For individual files and directories, the graphical method is much the easiest to use - just click on the ticks and blanks, then press the Accept button. The Recursive folders option lets you change permissions of a whole tree of files. The command line alternative is chmod - here are some examples of use Use chmod with care - if you make a mistake you might make all your files editable by everyone. Be especially careful when using the '-R' option - it can have far-reaching effects when you have symbolic links in the directory.

Changing a file's group

The chgrp command can be used to change the group of one of your files but you can only change it to a group you belong to. If you want files created in a particular directory to always belong to a certain group, you can avoid having to use chgrp repeatedly by setting up the directory in a special way. If you have a directory called foodir and you'd like all the files created there to be in the partIa1 group you can do the following (if you belong to partIa1)
   chgrp partIa1  foodir
   chmod g+s      foodir

umask

There's an alternative to retrospectively changing files' permissions - using the umask command you can arrange for new files to automatically have the desired permissions.

When a user creates a file it will be given default permissions. On the Teaching System those permissions give the user (but no-one else) read/write permission on their regular files and read/write/execute permission on their directories. These default permissions are set up in a configuration file at login by calling umask. If you type umask -S you will see your current settings. By default you should get u=rwx,g=,o=.

You can change this behaviour so that by default any new files you make can be read by anyone, or only by those in your current group. For example, typing umask u=rwx,g=rx lets group members read and execute your files.

Note that umask affects the behaviour of all future processes started from the window where umask was typed. It has no effect on programs which are already running.

Examples

Account Administration

Groups are set up by user-admin. start environments are set up by teaching-support. IIA project leaders can let students arrange themselves into groups if they ask tpl to create a student groups page for them - it will make life easier for user-admin too.

ACL

Since 2008 we've been using ACLs (Access Control Lists) to control access to some files (usually files used by groups for projects). The ACL control override the usual unix controls. To see if your files are under ACL control, open a terminal window and use ls ... as before. If there's a + after the permission flags in the output, the files are under ACL control. For example, the following files are ACLd

   drwxrws---+ 6 bin softdes1 4096 2009-05-15 11:23 softdes1
   drwxrws---+ 6 bin softdes2 4096 2009-05-15 11:25 softdes2

These displayed Unix permissions aren't to be trusted. To get the ACL information about a file or folder, use the getfacl command. For example, typing

   getfacl softdes1

gives informations about who can do what to the softdes1 folder.

© Cambridge University Engineering Dept
Information provided by Tim Love (tpl)
Last updated: May 2010