Linux Exercise 2 - File and Directory Permissions
📝 Linux Exercise: File and Directory Permissions
Section titled “📝 Linux Exercise: File and Directory Permissions”🎯 Objective
Section titled “🎯 Objective”Students will practice creating users and groups, assigning memberships, and setting file and directory permissions using both symbolic and octal syntax.
They will also experiment with creating, deleting, modifying, and executing files as well as creating, deleting, and entering directories under different permission setups.
They will document (protocol) every step they executed, including commands, outputs, and explanations.
🔨Task Instructions
Section titled “🔨Task Instructions”Part 1: User and Group Management
Section titled “Part 1: User and Group Management”-
Create two users
- Create
aliceandbob, each with a home directory. - Set passwords for both.
💡 Commands:
useradd,passwd - Create
-
Create a group
- Create a group called
projectteam.
💡Command:
groupadd - Create a group called
-
Assign users to groups
- Add both
aliceandbobtoprojectteamas supplementary members. - Change
alice’s primary group toprojectteam.
💡 Command:
usermod -aG,usermod -g - Add both
-
Verify memberships
- Show which groups
aliceandbobbelong to.
💡 Commands:
id,groups - Show which groups
Part 2: File and Directory Permissions
Section titled “Part 2: File and Directory Permissions”-
Create a project directory
- As root, create
/home/projectX. - Change its group ownership to
projectteam.
💡 Commands:
mkdir,chgrp - As root, create
-
Set permissions on the project directory
- Set permissions so that:
- User (owner) has
rwx - Group has
rwx - Others have no access
- User (owner) has
💡 Command:
chmod 770orchmod u=rwx,g=rwx,o=--- - Set permissions so that:
- Create and test files
- As
alice, create a file/home/projectX/plan.txtwith some text. - Check default permissions using
ls -l. - Try to open and modify the file as
bob. - Change permissions to allow
bobto write as well (chmod 664 plan.txt). - Try again as
boband record what happens.
- As
- Work with scripts
- As
alice, create a simple scripthello.shinside/home/projectX:#!/bin/bashecho "Hello from Alice's script!" - Check permissions with
ls -l hello.sh. - Try to run it as
alicewithoutxpermission (expect error). - Add execute permission for the user (
chmod u+x hello.sh). - Run it again successfully.
- Try running it as
bobbefore and after adding group execute rights.
- As
- Experiment with directories
- Inside
/home/projectX, create a subdirectoryreports/. - Set its permissions to
770. - As
bob, try to:- Enter the directory (
cd reports). - Create a new file inside.
- Delete that file again.
- Enter the directory (
- Then remove write permissions for the group and try the same steps again -> note what changes.
- Inside
-
Recursive permissions
- Apply permissions so the entire
/home/projectXtree is accessible by owner and group, hidden from others.
💡 Command:
chmod -R 770 /home/projectX - Apply permissions so the entire
Part 3: Cleanup
Section titled “Part 3: Cleanup”- Delete users and group
- Delete
aliceandbob(including home directories). - Delete the group
projectteam.
💡 Commands: userdel -r, groupdel
📑 Protocol (What to Hand In)
Section titled “📑 Protocol (What to Hand In)”Each student must create a protocol (log) that contains:
- Command executed
- Output received
- Explanation (1-2 sentences) of what the command did
- Observations when testing file/directory access with different users
Example:
Command: sudo chmod u+x hello.shOutput: (no output)Explanation: Gave user execute rights to the script hello.sh.Observation: Alice could run the script after adding +x, before that she got a "Permission denied" error.✅ Completion Criteria
Section titled “✅ Completion Criteria”- Users and group created, assigned, and deleted correctly.
- File and directory permissions set with both symbolic and octal syntax.
- Students tested file creation, deletion, modification, and execution under different permissions.
- Students tested directory creation, deletion, and entering (cd) under different permissions.
- Recursive permissions tested.
- Protocol includes commands, outputs, explanations, and observations.
- Student can explain differences in
r,w,xfor files vs directories.