Permissions: Going public (UNIX intro page 3)
Web pages or other documents you want to make visible to the public must be placed in the directory named "public_html"
However, even documents created in the public_html directory begin as "readable by author only." To finish the job of making your work public, Radford offers a utility on the myRU portal page, as described on my other instruction sheet.
You also can set access permissions without returning to the portal, by using the powerful UNIX "change mode" command called "chmod" for short.
The command has three parts: The command name, a code for the change you want made, and the name of the document whose "read" or "write" permissions you want to change. For purposes of this course, the simplest approach is to remember that "a+r" ("all read") is a code you can use to make any document readable by the global public. It will be writable only by you, the owner. You give the command in this form, where "filename.html" is the name of your document:
chmod a+r filename.html
That command should not be used on whole directories or combined groups of documents, programs and directories, because it will remove the "execute" permission. (Documents are not "executable.")
To add global read permission to directories and all the files they contain, use this command:
chmod -R a+rX directorynamehere
The first R and the final X must be capital letters. The "-R" means "recursive" (repeat the setting for all files). The capital X means to add the execute permission only to directories. An alternative is to use a numerical version of the chmod command, but be sure to type the numbers correctly:
chmod 755 filenamehere
That will add the "read" and "execute" permissions to any file, directory or program named. (Execute permission is not needed for documents, but setting it does no harm.)
The long file list command (ls -l) shows the chmod settings for all the files in the current directory. The letters d, r, w and x indicate whether the item is a directory (d) and whether the directory or file can be read (r), written (w), or executed as a program (x). "Written" really means "write, create or delete."
The first character in the line indicates directory (d) or file (-). The next three characters indicate the permissions granted to you, the owner of the file or directory. The three after that indicate permissions for members of a group (probably set to everyone who has an account on the server); the last three are permissions for everyone on the Internet. Of course you should never see a "w" in that last group of three, because you don't want to let other people write or delete your documents.
Simple example, here's how I made a new document "test.html" readable:
ruacad @ /home/rstepno/public_html > ruacad @ /home/rstepno/public_html > ls -l drwxr-xr-x 5 rstepno faculty 0 2009-03-24 15:00 09spring/ -rw-r--r-- 1 rstepno faculty 13140 2009-03-05 13:58 index.html -rw------- 1 rstepno faculty 15 2009-05-31 20:40 test.html [That shows the directory before I gave the "chmod" command below.] ruacad @ /home/rstepno/public_html > chmod a+r test.html [This will show the directory after the command. Notice the difference.] ruacad @ /home/rstepno/public_html > ls -l drwxr-xr-x 5 rstepno faculty 0 2009-03-24 15:00 09spring/ -rw-r--r-- 1 rstepno faculty 13140 2009-03-05 13:58 index.html -rw----r-- 1 rstepno faculty 15 2009-05-31 20:50 test.html
[The r-- means that "all others" can read the document. ]
Want to learn more?
For a more thorough explanation of chmod, including the "Symbolic method" of setting access with those "a+r" codes, see this detailed description at the University of Indiana. There are plenty of UNIX books available, and plenty of free tutorials and reference pages online. (Here's one.) If you are already fairly technical, each UNIX command has a "user's manual page," known as a "man page" available within the terminal, but written for experienced UNIX users. If you care to take a look, just type "man" followed by the name of the command you are interested in; for example, you can see all the variations of the "ls" command by typing "man ls" -- and there are plenty of them.