Chapter 3 some additional notes
Download
1 / 10

Chapter 3 Some additional notes… - PowerPoint PPT Presentation


  • 159 Views
  • Uploaded on

Chapter 3 Some additional notes…. File permissions A file has three types of permissions (read, write and execute). Available to three categories of users (user, group and others). Can see the permission settings using ls –l {apache:~/public_html/CS3375} ls -l total 6428

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Chapter 3 Some additional notes…' - ayanna-mcmahon


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Chapter 3 some additional notes
Chapter 3 Some additional notes…

  • File permissions

    A file has three types of permissions (read, write and execute).

    Available to three categories of users (user, group and others).

  • Can see the permission settings using ls –l

    {apache:~/public_html/CS3375} ls -l

    total 6428

    -rw-r--r-- 1 kkhan cs 3961 Jan 29 20:58 3375.html

    -rw-r--r-- 1 kkhan cs 70656 Jan 21 03:11 Syllabus_3375_sp08.doc

    -rw-r--r-- 1 kkhan cs 763392 Jan 7 13:27 Your_UNIX_2e.ppt

    - r-x - - - - - -

    The total line tells how many blocks (usually 1024 bytes per block) are contained in this directory.

    Directory, followed by three sets of 3 bits indicating permissions

    First set? Owner

    Second set? Group

    Third set? Others

    r stands for read, w stands for write, x stands for execute

Owner can read and execute this file


Chapter 3 some additional notes1
Chapter 3 Some additional notes…

Copying Permissions

As one other shortcut, it’s possible to tell chmod “give users of one class the same permissions that some other class has.”

Let’s say we have these files:

d------rwx joe acctg sales

-rw-r--r-- joe acctg info.dat

The other users have full permissions on the sales directory.

We’d like to say “ the user and group should be assigned (=) the permissions belonging to others.” That translates to:

chmod ug=o

Similarly, to make info.dat readable and writable to the group, we can say:

chmod g=u info.dat (you can read this as “the group is assigned (=) the permissions currently held by the user.”)

You may also use + and - to add and subtract the permissions that currently belong to a different class of user.

You can’t mix the standard permissions (r, w, and x) with the coyping shortcuts. chmod will protest if you give it something like this:

chmod g=wu info.dat


Need to be able to change the file permissions
Need to be able to change the file permissions

  • Why?

    • Protect files from accidental deletion or modification (archive)

    • Allow team members to read, modify, execute, possibly even delete a file without having to send them a copy

    • Setting up your webpage on unix – have to make the html files accessible or no one will be able to see it!

  • Unix command is chmod

    • Command allows us to change the permission settings

  • Examples (can use relative or absolute permissions):

    chmod o+rwx testfile1

    -r-x---rwx 1 kkhan cs 24 Sep 7 10:41 testfile1

    // “o” is for “other”, “+” means add permission


Need to be able to change the file permissions1
Need to be able to change the file permissions

  • Examples cont.

    Change it back?

    chmod o-rwx testfile1

    Results in:

    -r-x------ 1 kkhan cs 24 Sep 7 10:41 testfile1

    // “-” means remove permission

    Can also use absolute (binary) mode

    chmod 507 testfile1

    Results in:

    -r-x---rwx 1 kkhan cs 24 Sep 7 10:41 testfile1

    5 0 7

    101 000 111

    r-x - - - rwx

    (Bits are set or cleared)


Need to be able to change the file permissions2
Need to be able to change the file permissions

  • Access to files is not independent of the permissions on the directories

  • The directory is the “parent”; permissions on the parent cannot be over-ridden by permissions on its files

  • Examples

  • Directory is set with no write access

    • Cannot add or delete a file in the directory no matter what its permissions are

      • Question: could we edit a file in this directory?

        • Only if we have write permission for the file

  • Directory is set with no read or execute access

    • Question: could we run an html file in this directory?

      • No (this is a common problem setting up webpages)


Need to be able to change the file permissions3
Need to be able to change the file permissions

  • Man chmod

    chmod [-fR] absolute-mode file...

    chmod [-fR] symbolic-mode-list file...

    -f Force. chmod will not complain if it fails to change the mode of a file.

    -R Recursively descends through directory arguments, setting the mode for each file as described above.

    Problem: I’m building my website and I want to set all my files in the directory public_html so everyone can read and execute my html file

    chmod –R a+rx public_html

    Review: chmod Solves Problems http://catcode.com/teachmod/no_prob.html


File permission exercise
File Permission Exercise

Set the permissions as follows:

testdir1 group & other has no access

testfile1.html group & other has no access

testfile2.html group & other has read access

testfile3.html group & other has write access

testfile4.html group & other has execute access

testfile5.html group & other has read and execute access

testfile6.html group & other has read and write access

testfile7.html group & other has write and execute access

testfile8.html group & other has read, write, and execute access


File permission exercise1
File Permission Exercise

testdir2 group & other has read access

// 8 files

testdir3 group & other has write access

// 8 files

testdir4 group & other has execute access

// 8 files

testdir5 group & other has read and execute access

// 8 files

testdir6 group & other has read and write access

// 8 files

testdir7 group & other has write and execute access

// 8 files

testdir8 group & other has read, write, and execute access


File permission exercise2
File Permission Exercise

Now, try to:

display the contents of each directory

e.g., ls testdir1

display a long listing of each directory

e.g., ls –l testdir1

why don’t these two list commands behave the same way?

display the contents of each file in each subdirectory

e.g., more testfile1.html

change the contents of each file

e.g., echo “trying to change the file” >> testfile1.html

delete each file

e.g., rm testfile1.html


File permission exercise3
File Permission Exercise

To test the ability to load a .html file in a browser, you need to set up a softlink (aka symbolic link) under your public_html directory

cd

cd public_html

ln -s <original> <link name>

- creates a softlink (called link name), which points to the original subdirectory

e.g., ln –s ~kkhan/public_html/testfiles testdir

cd <link name> takes you to the original subdirectory

cd testdir

Now, in the browser (for example running on the pc) you can use the open file option to test loading the .html files

If the file loaded successfully, then there is a brief text displayed from the file

Try loading one that definitely should work:

testdir8/testfile8.html


ad