Tutorial 3

 

In this tutorial, we are going to exercise our knowledge on file permissions.

 

Why need to change file permissions?

  • It protects files from accidental deletion or modification;

  • It allows team members to read, modify, execute, and possibly even delete a file without having to send them a copy;

  • When setting up your webpage on UNIX, you have to make the html files accessible or no one will be able to see it!

  • ...

 

In order to carry out the following exercises, please follow the following instructions:

  • Work in pairs;

  • Logon a machine from cs1 to cs3 at utdallas.edu, type in your UTD netid and password one at a time followed by pressing the "Enter" key;

 

You can use either putty or Xmanager to access these UNIX machines.

 

For detail instructions on login, please refer back to Tutorial 1.

 

Create Directories and Files

 

The goal is to create three subdirectories with eight testfiles in each one to match the permissions, and your partner will try out some basic commands on the files:

    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

    testdir2 group & other has read access
    // 8 files

    testdir3 group & other has write access
    // 8 files
 

Follow the steps below to create a subdirectory where you can work on this tutorial. First, create a new subdirectory:

{cs1:~} mkdir tutorial3
{cs1:~} ls -l
total 178
drwx------ 4 weiminma sn 1024 Jan 19 2008 aos
drwx--x--x 2 weiminma cs 512 Sep 8 12:24 tutorial3
drwx------ 16 weiminma sn 512 Sep 3 16:59 working_directory

 

Then change the permissions for group and other to read and execute on the subdirectory "tutorial3":

{cs1:~} chmod 755 tutorial3
{cs1:~} ls -l
total 176
drwx------ 4 weiminma sn 1024 Jan 19 2008 aos
drwxr-xr-x 2 weiminma cs 512 Sep 8 12:24 tutorial3
drwx------ 16 weiminma sn 512 Sep 3 16:59 working_directory

 

The commands that create the above three directories and eight files with above permissions are as follows. But first, we want to copy the directories and testfiles using the following commands:

 

{cs1:~} cd tutorial3
{cs1:~/tutorial3}

{cs1:~/tutorial3} cp -pr ~weiminma/course_related/TA_S08/CS5375/tutorials/Tutorial3/testdir1 .

{cs1:~/tutorial3} cp -pr ~weiminma/course_related/TA_S08/CS5375/tutorials/Tutorial3/testdir2 .

{cs1:~/tutorial3} cp -pr ~weiminma/course_related/TA_S08/CS5375/tutorials/Tutorial3/testdir3 .

 

Then we are going to see whether everything is ok by the following command:

 

{cs1:~/tutorial3} whoami

weiminma

{cs1:~/tutorial3} ls -lR

.:
total 6
drwxr-xr-x 2 weiminma cs 512 Sep 7 20:34 testdir1
drwxr-xr-x 2 weiminma cs 512 Sep 7 20:35 testdir2
drwxr-xr-x 2 weiminma cs 512 Sep 7 20:35 testdir3

./testdir1:
total 16
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:31 testfile1.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile2.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile3.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile4.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile5.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:33 testfile6.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:33 testfile7.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:33 testfile8.htm

./testdir2:
total 16
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:36 testfile1.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:36 testfile2.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:36 testfile3.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:36 testfile4.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:36 testfile5.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:36 testfile6.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:36 testfile7.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:37 testfile8.htm

./testdir3:
total 16
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:37 testfile1.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:37 testfile2.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:37 testfile3.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:37 testfile4.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:37 testfile5.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:37 testfile6.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:38 testfile7.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:38 testfile8.htm

 

Change File Permissions

 

Now, we want to change the files' permission, and "chmod" is the command which can be used to change the file permissions. Its syntax is:

 

chmod [–R] mode file …

 

Permissions can be changed in different manner. The “mode” can be either absolute mode or symbolic mode. The “mode” consists of three parts:

  1. User category (user, group, other)
  2. The operation to be performed (assign or remove a permission)
  3. The type of permission (read, write and execute)

 

For demonstration purpose, we will use the directories and files copied above. There are three copied subdirectories, i.e., "testdir1" to "testdir3", with the same permissions and each of these directories has eight files with the same permissions too. Their permissions can be viewed by the command shown above.

 

Now we want to change the subdirectories' permissions first, the commands to change them are as follows:

{cs1:~/tutorial3} chmod 700 testdir1

{cs1:~/tutorial3} chmod 744 testdir2

{cs1:~/tutorial3} chmod 722 testdir3

{cs1:~/tutorial3} ls -l
total 10
drwx--x--x 5 weiminma cs 512 Sep 7 21:24 .
drwxr-xr-x 7 weiminma cs 512 Sep 7 21:17 ..
drwx------ 2 weiminma cs 512 Sep 7 20:34 testdir1
drwxr--r-- 2 weiminma cs 512 Sep 7 20:35 testdir2
drwx-w--w- 2 weiminma cs 512 Sep 7 20:35 testdir3
 

The next step is to change the files' permissions of the subdirectory "testdir1", and the way to change the files' permission of the subdirectory "testdir2" and "testdir3" is the same. Before the permission change, the file's permissions for the subdirectoriy "testdir1" is as follows:

{cs1:~/tutorial3} cd testdir1
{cs1:~/tutorial3/testdir1} ls -l
total 16
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:31 testfile1.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile2.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile3.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile4.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile5.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:33 testfile6.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:33 testfile7.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:33 testfile8.htm

 

Then we apply the following commands to change the file's permissions as specified at the beginning of the tutorial:

{cs1:~/tutorial3/testdir1} chmod 700 testfile1.htm
{cs1:~/tutorial3/testdir1} chmod 744 testfile2.htm
{cs1:~/tutorial3/testdir1} chmod 722 testfile3.htm
{cs1:~/tutorial3/testdir1} chmod 711 testfile4.htm
{cs1:~/tutorial3/testdir1} chmod 755 testfile5.htm
{cs1:~/tutorial3/testdir1} chmod 766 testfile6.htm
{cs1:~/tutorial3/testdir1} chmod 733 testfile7.htm
{cs1:~/tutorial3/testdir1} chmod 777 testfile8.htm

 

Then we want to take a look of the file's permissions now:

{cs1:~/tutorial3/testdir1} ls -l
total 20
drwx------ 2 weiminma cs 512 Sep 7 20:34 .
drwx--x--x 5 weiminma cs 512 Sep 7 21:24 ..
-rwx------ 1 weiminma cs 303 Sep 7 20:31 testfile1.htm
-rwxr--r-- 1 weiminma cs 303 Sep 7 20:32 testfile2.htm
-rwx-w--w- 1 weiminma cs 303 Sep 7 20:32 testfile3.htm
-rwx--x--x 1 weiminma cs 303 Sep 7 20:32 testfile4.htm
-rwxr-xr-x 1 weiminma cs 303 Sep 7 20:32 testfile5.htm
-rwxrw-rw- 1 weiminma cs 303 Sep 7 20:33 testfile6.htm
-rwx-wx-wx 1 weiminma cs 303 Sep 7 20:33 testfile7.htm
-rwxrwxrwx 1 weiminma cs 303 Sep 7 20:33 testfile8.htm

 

Repeat the above steps for the files inside the subdirectory "testdir2" and "testdir3".

 

Work On Your Peer's Files

 

For each student, you need to to "cd" to your peer's subdirectories, the following command will let you do that. For instance, your netid is "weiminma", and you want to "cd" to your peer's subdirectory "tutorial3" (your peer's netid is "johndoe"), then you can do this:

{cs1:~} whoami

weiminma

{cs1:~} cd ~johndoe/tutorial3

{cs1:/net/core/export/home/cs/001/j/johndoe/tutorial3}

 

There are three subdirectories underneath the subdirectory "tutorial3". If you want to see the subdirectories  inside the directory "tutorial3", you can type the following commands:

{cs1:/net/core/export/home/cs/001/j/johndoe/tutorial3} ls -l
total 862
drwxr-xr-x 2 johndoe cs 512 Sep 7 20:34 testdir1
drwxr-xr-x 2 johndoe cs 512 Sep 7 20:35 testdir2
drwxr-xr-x 2 johndoe cs 512 Sep 7 20:35 testdir3
 

Then you need to try to change to each of the three subdirectories. For instance, you want to change to your peer's subdirectory "testdir1", then you need to do the following:

{cs1:/net/core/export/home/cs/001/j/johndoe/tutorial3} cd testdir1

 

 

The output of the above command is not listed here. What could happen? Are you allowed to "cd" to your peer's "testdir1" subdirectory? Why or why not?

 

 

Then try to list the files underneath your peer's subdirectory "testdir1" using the following command:

{cs1:/net/core/export/home/cs/001/j/johndoe/tutorial3} ls -l testdir1
 

 

The output of the above command is not listed here. What could happen? Are you allowed to "ls" the files of your peer's "testdir1" subdirectory? Why or why not?

 

 

The next step is to try to modify the contents of each file by appending a line to the bottom using ">>", and remove each file that the other person on the team owns.

 

For example, testfile8.htm looks like this before the modification:

{cs1:/net/core/export/home/cs/001/j/johndoe/tutorial3/testdir1} cat testfile8.htm
 

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<p>This is the &quot;testfile8&quot; inside the directory &quot;testdir1&quot;.</p>
</body>

</html>

 

 

You can try to modify the file by adding a line at the bottom of it like this:

{cs1:/net/core/export/home/cs/001/j/johndoe/tutorial3/testdir1} cat >> testfile8.htm
this is a new line.

'CTRL-D'
 

If the file is modified, then it would like this:

{cs1:/net/core/export/home/cs/001/j/johndoe/tutorial3/testdir1} cat testfile8.htm
 

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<p>This is the &quot;testfile8&quot; inside the directory &quot;testdir1&quot;.</p>
</body>

</html>

this is a new line.

 

 

If you are not allowed to read the file, then how can you check to see if it has been modified or not?

 

If you want to remove the files inside the subdirectory "testdir1" and the other subdirectories, you can try the following command.

{cs1:/net/core/export/home/cs/001/j/johndoe/tutorial3} rm -r testdir1
 

 

The output of the above command is not listed here. What could happen? Are you allowed to remove the files of your peer's "testdir1" subdirectory? Why or why not?

 

 

Depends on the permissions of a file, you may or may not be able to remove a file. Also follow the above steps for other files underneath your peer's subdirectory "testdir1" and other files underneath your peer's subdirectory "testdir2" and "testdir3".

 

Exercise: Please identify which three permission bits apply to you?

Note: Assignment 2 will continue on to try all possible combinations of the permission bits.