




















| |
Lab 8
(Chapter 8)
Learning Objectives
- To learn concept of file
access permissions/privileges in UNIX, i.e., types of users and types of file
privileges
- To learn how to determine
access privileges for a file
- To learn how to set or
change access privileges for files that you own
- To learn what kinds of
access privileges are needed for various file operations such as copy and move
- To learn how to set default
access permissions for newly created files and directories
- To learn how to set and
reset special access privileges bits: Set-User-ID bit, Set-Group-ID bit, and
Sticky bit.
Lab Work
In UNIX, there are three types of users
of a file: user (the owner of the file), group (users in owner’s group), and
others (everyone else). File permissions/privileges for each user type may be
set to a combination of read, write, and execute. Execute permission for a
directory means that it can be searched.
- Log on to your UNIX system
- Write
down the following and show the session that you used to obtain the required
information:
- Your
user name (also known as login name)
- Your
user ID
- Your
group ID and group name
- User
names of users in your group
- Number
of groups that you are a member of
- Write
down the user names of the users on your system who are members of more than
one group, including the names of their group
- What are
the permissions for your home directory set by your system administrator? What
command did you use to answer the question? Show your session.
- Suppose
that you want to block everyone at the main door of your directory hierarchy
(i.e., your home directory), as shown in Figure Lab7.1. Take the necessary
steps to do this. Show the session that you used to accomplish the task and
confirm that the task has actually been done.
-
Consider the following files (or directories): /, /etc/passwd, /usr/bin/df, ~,
.profile (in your home directory). Show the long listings for these files and
complete the following table. Show file size (in bytes) for non-directory
files only.
File
|
Type |
Permissions
|
Link Count |
Owner |
Group |
File Size |
Date Last Modified |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
For files and directories given in 5, show permissions as octal numbers.
- Set
permissions for the temp, professional, and personal directories in your home
directory to read, write, and execute for yourself, and read and execute for
everyone else. If the permissions are already set like this, keep them so.
Create a directory hierarchy d1, d2, and d3 directories under the ~/temp
directory. Now create a file, called f1, under the d1 directory by using
touch command, which
can be used to create empty files. Read the manual page for
touch for further
information. Show permissions for d1, d2, d3, and f1. Capture your session and
draw the picture for the ~/temp directory hierarchy.
- Change
directory to your home directory. Set permissions for ~/temp to execute only
and run the ls –ld temp command. Now execute the
ls –l temp command.
What happens? Does it make sense to you? What are the minimum permissions
required for the ls –l temp
directory executes successfully. Set permissions for the temp directory to the
minimum required and re-execute the
ls –l temp command.
Show the output of this command.
- Display
the current value of your ‘umask’. Change directory to your home directory and
create a file f2 and a directory d11 under the ~/temp/d1 directory. Use the
touch command for
creating f2. Change directory to ~/temp/d1. Use an editor to create a file
hello.c under the temp directory that contains the following C program.
#include <stdio.h>
main(void)
{
printf (“Hello, world!\n”);
}
Now run the
gcc –o greeting hello.c command to generate the executable for the C
program in the hello.c file and place it in the greeting file. Display long
listing of d1 to display permissions for f2, hello.c, greeting, and d1.
Change the mask value to 077
and repeat the above task but use the ~/temp/d2 directory this time. Do the
permissions for f2, hello.c, greeting, and d21 under the ~/temp/d2 directory
make sense with the new umask value? Finally, fill in the following table and
explain the relationship between the ‘umask’ value and permissions for new text
files, executable files, and directories.
Note that in UNIX the default permissions for executable files
and directories are 777, and for text files permissions are 666.
umask Value |
Permissions for Files
|
f2 |
hello.c |
greeting |
d11 / d21 |
|
|
|
|
|
|
|
|
|
|
- Create
the ~/temp/d3/d31 directory with
mkdir ~/temp/d3/d31.
Display the long listing of the newly created directory. If you cannot do this
because of improper permissions on a component of the pathname, set the
minimum permissions required for this operations on the pathname and then
display the long listing. Now copy ~/temp/d1/f1 and move ~/temp/d2/f2 to the
~/temp/d3/d31 directory and then remove ~/temp/d1/f1 with the following
commands:
cp ~/temp/d1/f1 ~/temp/d3/d31
mv ~/temp/d2/f2 ~/temp/d3/d31
rm ~/temp/d1/f1
What are the minimum permissions needed for
these files and directories in order for the copy, move, and remove operations
to be successful? Set permissions on the above files and directories to these
minimum values and complete the copy, move, and remove operations. Show the
minimum permissions needed in the following table and capture your session
below.
Operation
|
Minimum Required Permissions
|
temp |
|
d2 |
d3 |
d31 |
f1 |
f2 |
mkdir
~/temp/d3/d31 |
|
|
|
|
|
|
|
ls –l
~/temp/d3/d31 |
|
|
|
|
|
|
|
cp
~/temp/d1/f1 ~/temp/d3/d31 |
|
|
|
|
|
|
|
mv
~/temp/d2/f2 ~/temp/d3/d31 |
|
|
|
|
|
|
|
rm
~/temp/d1/f1 |
|
|
|
|
|
|
|
- Log
out.
|