File modes

In the unix filesystem, every file has a "mode" which controls the ability of people and programs to access that file. A user can be allowed to read a file, or to modify a file ("write" to the file), or neither. Files also have an 'x' permission which will be important for us for directories. To specify a file in a directory, a user needs 'x' permission on the directory.

The web server runs as a particular (fake) user on the CDF computers. By default it cannot read your files. This is good; you don't want to publish a private file to the whole world accidentally!

So there's a bit of a procedure required to publish your HTML files. The web server will not publish files out of your home directory itself, but only out of a subdirectory named "public_html" and below; and you need to give it appropriate access permissions to your files.

First of all, you need to create the public_html directory. You can do this in the file browser ("Konqueror"), or you can simply type "mkdir public_html" in a terminal window at the "%" prompt.

You need to give the web server 'x' permission on your home directory and on the public_html directory. You can type:

chmod a+x . public_html
if you are cd'd to your home directory. This specifies two directories to change the permissions on, because after you type "chmod a+x", you list any number of files (or directories) on the command line, and it will apply this change to all of them. The second directory we're asking to change permissions on is the subdirectory public_html, and the first is the current directory -- "." is a special name like "..", meaning the current directory (as you know ".." means the parent directory) -- if you're cd'd to your home directory, "." is your home directory.

If this chmod command gives no response, it's good. Any response will be error messages, which you should attempt to decode or e-mail to me to decode, or just check your command-line again carefully to see what you mistyped. If all's well, you'll get the '%' prompt again.

When you put an HTML file in your public_html directory, you need to give it 'r' permission for the web server to be able to read it. You can do this with, for example,

chmod a+r public_html/webpage.html

(And in case you're wondering, that "a", in the strings "a+x" and "a+r", means "all" -- you are changing the permissions for everybody.)

You can then use the "-l" option to the "ls" program to see the file mode information. Example (except that you likely have a more complex shell prompt than the simple "%" shown below):

% ls -l public_html/software.html
-rw-r--r--    1 ajr      instrs        200 Oct 25 22:12 public_html/software.html
% 

To interpret the mode information, you have to read the letters in groups.

First of all, the first character there is either 'd' for directory or '-' if it's a plain file.

Then the permissions are in groups of three characters. The first three are for the owner of the file, which farther along the line we can see is ajr. I have 'r' (read) and 'w' (write) permission, but not 'x' (which would not be useful on an HTML file anyway).

The next three are for the "group" of the file. "instrs" is a group containing course instructors. I'm in the group "instrs", but since I'm the owner of the file, my permissions are as above. Everyone else in the group instrs has the permissions indicated by the middle group: They can read the file ('r'), but they can't write it and they don't have the 'x' permission (the next two dashes).

The final three are for everyone else. Users who are neither ajr nor in group instrs have those permissions: again, read-only. It's very common to use the same set of permissions for the 'group' and 'other' categories.

It's slightly harder to look at directories with "ls -l". If you do an "ls -l" of a directory, it shows you what's inside the directory! But there is an option, "-d", which says "even if this is a directory, show me the information about this item I'm naming, not its contents".

Furthermore, you can combine the options "-l -d" into the shorthand "-ld".

% ls -ld public_html
drwx------    2 ajr      instrs        512 Oct 25 22:12 public_html
% 
That shows that the web server won't be able to search my public_html directory. I have to change the permissions:
% chmod a+x public_html
% ls -ld public_html
drwx--x--x    2 ajr      instrs        512 Oct 25 22:12 public_html
% 
I also need to change the permissions for my home directory. Except that actually I've already done this so that you could access /u/ajr/104 for earlier assignments! So, here I am checking that it's already ok:
% ls -ld .
drwx--x--x   28 ajr      instrs       2048 Oct 25 22:11 .
% 


[assignment three questions and answers]
[main course page]