Changing File Permissions

Oftentimes, when attempting to post a document to the course website, you'll find that the public doesn't have permission to view the document. When trying to access the document you'll get an error like:
Forbidden
You don't have permission to access /~cs116/Tutorials/tutorial5_soln.shtml on this server.
The following information will allow you to fix this problem.

The short version

The short version of how to fix this by running the following command in terminal: chmod 755 [filename]

Note that this command must be run from within the directory that the file is located. ie, in the example above we would have to run "chmod 755 tutorial5_soln.shtml" from within the Tutorials folder. (See __ on how to find your way around in terminal).

There is a similar command for changing the permissions on an entire folder: chmod -R 755 [foldername]

Note that this command must be run from the directoy that the folder is contained within.

The long version

I've made a folder in my u directory called "Chmod-Test" and in it are 2 .txt files that I have created. Calling "ls -l" in this directory gives the following information:

-rwx------ 1 cs116 cs116 23 Feb 21 09:37 test1.shtml
-rwx------ 1 cs116 cs116 23 Feb 21 09:37 test2.shtml
At the beginning of each line are 10 characters. The first character is either "d" or "-" and the next three sets of three can be "rwx", "---" or some combination (ie, "-wx" or "r-x").

It may be more helpful to divide the characters up into columns like so:

1  2   3   4      5     6
- rwx --- --- 1 cs116 cs116 23 Feb 21 09:37 test1.shtml
- rwx --- --- 1 cs116 cs116 23 Feb 21 09:37 test2.shtml
Column 1 is the file type and unimportant for this particular topic.

Column 2 represents the permissions for the user (ie, the creator of the file, presumably you or someone else within the ISG). The user is given in column 5.

Column 3 represents the permissions for the group. In this case the group is "cs116" which is given in column 6.

Column 4 represents the permissions for "others." This will generally be students in the course who are trying to access the file via the course website. By default, they have absolutely no access to the files.

r means that the user/group/other is able to read the file
w means that the user/group/other is able to write to the file
x means that the user/group/other is able to execute the file
a '-' in any of the corresponding spots means that the user/group/other does not
have that particular permission.
If we call "chmod 755 test1.shtml" and then "ls -l":
-rwxr-xr-x 1 cs116 cs116 23 Feb 21 09:37 test1.shtml
-rwx------ 1 cs116 cs116 23 Feb 21 09:37 test2.shtml
And so the group and "others" (ie, the students accessing the course website) are now able to read and execute test1.shtml but they cannot write (ie, edit) the file.

The general form of the chmod command is: "chmod who=permissions filename"

where who is a list of letters from
u - user who owns the file
g - group the file belongs to
o - other users
a - all of the above
and permissions is a similar list of r, w, and/or x (as above).

So for example, if we call "chmod go=x test2.shtml" and then "ls -l":

-rwxr-xr-x 1 cs116 cs116 23 Feb 21 09:37 test1.shtml
-rwx--x--x 1 cs116 cs116 23 Feb 21 09:37 test2.shtml
If we now call "chmod ugo=x test2.shtml" (or "chmod a=x test2.shtml) and then "ls -l":
-rwxr-xr-x 1 cs116 cs116 23 Feb 21 09:37 test1.shtml
---x--x--x 1 cs116 cs116 23 Feb 21 09:37 test2.shtml
Notice that the user is no longer able to read or write test2.

Example: Posting a tutorial to the course website

  • Firstly, make sure that the tutorial you are trying to post is in the "Tutorials" folder which, in turn, is located within the "public_html" folder (you will also need to edit 'tutorials.shtml' located in public_html to include the file)
  • Next, in terminal, navigate into the tutorials folder (for example, if you are currently in your u directory (which is the default when you log into terminal) then enter 'cd ../../public_html/Tutorials')
  • Lastly, enter 'chmod 755 tutorialX.shtml' where X is the number of the tutorial
  • Equivalently, you could enter 'chmod go=rx tutorialX.shtml'
  • Now, the file should be accessible on the course website

-- GradonNicholls - 21 Feb 2013

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2013-02-22 - GradonNicholls
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback