0% found this document useful (0 votes)
20 views

Lab Assignment_4-Solution (5)

Uploaded by

hnour8631
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Lab Assignment_4-Solution (5)

Uploaded by

hnour8631
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1st year of the first cycle Higher School of Computer Science

Course : Introduction to operating system 1 Sidi Bel Abbes (ESI-SBA)

Lab assignment N°4


Ownership and Permissions

Module 1 :
1. Use the script utility to capture your session.
Solution.
script Lab4

2. What is your user id ? To which groups your account is associated ? Open the /etc/passwd file,
describe its content. Open /etc/group file, describe its content.
Solution.
id

cat /etc/passwd

cat /etc/group

3. Create a new directory called Lab4 in your home directory. Show the access rights (permissions)
of Lab4.
Solution.
cd /home/user

mkdir Lab4

ls -ld Lab4

4. Create a non-empty file in Lab4 directory called STP1. Show the access rights of STP1.
Solution.
cat > Lab4/STP1

Hello students,

Ctrl-c

ls -l Lab4/STP1

5. Use one command of the symbolic-relative mode to change the access rights of STP1, so that you
remove read permission from user. Show the content of STP1, what happens ?
Solution.
chmod –r Lab4/STP1

cat Lab4/STP1 //permission denied since the user has no read permission (r)

6. Append the content of STP1, establish for the user the read access right of STP1. Show the
content of STP1, what happens ?
Solution.
cat >> Lab4/STP1

Our Lab today concerns ownership and permissions in Linux OS.


ctrl-c

chmod +r Lab4/STP1

cat Lab4/STP1 // we can view the content of the file since we have the read permission (r)

Hello students,

Our Lab today concerns ownership and permissions in Linux OS.

7. Use one command and the symbolic-relative mode to change the access rights of STP1, so that
you remove write permission from the user. Append the content of STP1 ? What happens ?
Solution.
chmod -w Lab4/STP1

cat >> Lab4/STP1 //permission denied since the user has no write permission (w)

8. Delete STP1 file and create two new files : non-empty regular files STP2, STP3 and a script file
STP4.sh Show the access rights of STP3 and STP4.sh
Solution.
rm Lab4/STP1

cat > Lab4/STP2 Cat > Lab4/STP4.sh


Our second regular file ! #!/bin/bash
ctrl-c # our first script
Echo “Hello World”
cat > Lab4/STP3 ctrl –c
Our second regular file !
ctrl-c

ls -l Lab4/STP2 Lab4/STP4.sh

9. Show the access rights of STP4.sh. Execute the script STP4.sh, what happens ?. Establish for the
user the execute access right of STP4.sh and try to execute it once again, what happens ?

Solution.
Remark : for kali Lunix distro replace #!/bin/bash with #!/usr/bin/zsh

./STP4.sh // permission denied since the user has no execute permission (x)

chmod +x Lab4/STP4.sh

./STP4.sh // Hello world will be displayed on your terminal, i.e., the execution of the script
turns possible after establishing the x (execute) access right.

10. Change the access rights of Lab4, so that you remove write permission from the user. Delete
STP2 file, what happens ? Establish for the user the write access right of Lab4, and remove the
write access right of STP2, delete STP2, what happens ?

Solution.
chmod –w Lab4
rm Lab4/STP2 // permission denied since Lab4 has no write access right (w)

chmod +w Lab4

chmod -w Lab4/STP2

rm Lab4/STP2

STP2 file can be deleted, however a message is displayed on the terminal for file deletion
confirmation, in order to forbid this message from being displayed, you add -f option of rm
command.

rm -f Lab4/STP2

chmod +w Lab4

11. Change the access rights of Lab4, so that you remove read permission from the user. Show the
content of the directory Lab4, what happens ? Show the content of STP3 and STP4.sh, what
happens ? Establish the read access right of Lab4
Solution.
chmod -r Lab4

ls Lab4 // permission denied since Lab4 has no read access right (r)

cat Lab4/STP3

cat Lab4/STP4.sh

//Doable since both files have the read permission that allows to display their content.

chmod +r Lab4

12. Change the access rights of Lab4, so that you remove execute permission from the user. Describe
what happens when applying commands to Lab4. Establish the execute access right of Lab4
Solution.
chmod -x Lab4

// whatever the command that we apply to the directory Lab4, we figure out on the terminal
a permission denied message. Only one command is possible, which is chmod command that
permits to change the access rights of the directory.

13. What is your current umask set to. What are the default permissions of the associated
directories and files ?
Solution.
umask

For UBUNTU distribution the default permissions are : 775/664 (umask : 002).

For KALI distribution the default permissions are : 755/644 (umask : 022).

14. Set your umask to 023. What command did you type ? With this new umask of 023, what is the
expected permissions of new directories and files.
Solution.
umask 023
15. While in your home directory Lab4, create a new directory called newdir. Show the access rights
of newdir. Does it match your expected permissions based on your umask ?
Solution.
cd Lab4

mkdir newdir

ls -dl newdir

16. Now, go inside newdir, and create two regular files called file1 and file2 using a single command.
Use a single command to display the permissions of the two files. Does the output match your
expected set of permissions for a new file based on your umask ?
Solution.
cd newdir

touch file1 file2

ls -l file1 file2

17. What is the command to view the file1 file owner (user) and group ?
Solution.
ls -l file1

18. Change the file1 file owner to another user of your choice. View the modification.
Solution.
sudo chown root file1

ls -l file1

19. Change the file1 file group to another group of your choice. View the modification.
Solution.
sudo chgrp root file1

ls -l file1

20. Perform the changes of both file1’s file owner and group using one command. View the
modification.
Solution.
sudo chown user:user file1

ls -l file1

21. Exit the script.


Solution.
exit

You might also like