Course Links

Exercises

Resources

External

It is essential that you understand Unix file access permissions and set them correctly. Incorrect settings may leave your source program visible to others in class, which is a violation of the Honor Code. This document will tell you everything you need to know in order to check and set the access permissions.

Viewing Permission Settings

Permission settings can be seen by using the -l flag argument to the ls command. (That's "dash-ell", not "dash-one".)

$ ls -l
total 12
-rw-r--r--  1 nhowe faculty 1026 Jan  5 10:44 HelloWorld.class
-rw-r--r--  1 nhowe faculty  380 Jan  5 10:47 HelloWorld.html
-rw-------  1 nhowe faculty  439 Jan  5 10:43 HelloWorld.java

This example shows the correct settings for a simple project. Note that there are three files, each with the same name but a different suffix extension. Files with a .java suffix are source code, and should not be shared. Files with a .class suffix are compiled Java bytecode and may be made readable so that the results can be viewed in a web browser. The .html file is an HTML wrapper file that tells the browser where to find the .class file and what to do with it.

The permission settings are the first ten characters in each line. The first holds special codes and may be ignored for our purposes. Characters 2-4 show the permissions for the file owner (nhowe), 5-7 for the group that the file belongs to (faculty), and 8-10 for everybody else. The letters r, w, and x stand for permission to read, write, and execute the file, respectively; a hyphen in any position indicates no permission to perform the corresponding action. The owner of the files may read or write (modify) all of them. Everybody else may read HelloWorld.class and HelloWorld.html, but not HelloWorld.java. Since none of the files above are runnable files, nobody can execute them. (If the permissions were changed to make the file executable, and somebody attempted to run them, an error would result.)

Setting Permissions

Files and directories may not be created automatically with the proper permission settings. Therefore it is essential that you check the permissions on your source code files and change them if necessary. The Unix command to change file permissions is called chmod. This can be used in many different modes (which you can read about by typing man chmod), but we will only look at the few which will be needed for this course. The command line arguments for chmod will consist of a permission code number and the name of the file to apply the code to. We will use permission codes consisting of three-digit numbers, where each digit gives the permissions for one of the three levels (user, group, other) and is composed of a binary code (4 = read, 2 = write, 1 = execute; sums indicate combinations). The examples below will accomplish everything we need.

Your source code (.java files) should be readable and writable by you and nobody else. The code to achieve this is 600.

$ chmod 600 HelloWorld.java

Your compiled code and web pages (.class and .htmlfiles) should be readable and writable by you, and readable by everybody else. The code to achieve this is 644.

$ chmod 644 HelloWorld.class
$ chmod 644 HelloWorld.html

Any directories inside public_html should be readable, and executable by everybody, and also writable by you. The code to achieve this is 755.

$ cd ~/public_html/csc112
$ mkdir HelloWorld
$ chmod 755 HelloWorld

Permissions and Windows

If you work using Java (JDK or J++) on a PC, you must be aware that there is no protection mechanism for your files. If you store your files on the local C: drive, you must transfer them elsewhere and remove them from the local disk before leaving. Otherwise, anybody who uses the machine after you leave can look into your work. Moreover, your files can be removed by anybody, so you may not find them later when you return to the same machine. Using Java locally allows you to view the applet by loading the html file in Explorer using File/Open File instead of File/Open Location. This might work faster and be more convenient. When you are done, you must transfer the .html, .java and .class files to the appropriate directory on the server, and turn the protection bits on, as explained above.