📝 Update Phase 1 & 2 with Alpine-specific fixes (ash vs bash, rsync install, SSH key details)
This commit is contained in:
@@ -68,28 +68,53 @@ uname -r # Kernel version
|
||||
## 🎯 Exercise 3 — File Permissions
|
||||
|
||||
```bash
|
||||
# Check permissions
|
||||
ls -la /root/lab/notes/
|
||||
# Step 1 — Check current permissions
|
||||
ls -la /root/lab/
|
||||
|
||||
# Change permissions
|
||||
chmod 644 /root/lab/notes/hello.txt
|
||||
chmod 755 /root/lab/scripts
|
||||
# Step 2 — Understand the columns
|
||||
# -rw-r--r-- 1 root root 20 May 21 file
|
||||
# ─┬─ ─┬─ ─── permissions, owner, group, size, date, name
|
||||
# │ └── user/group/other (r=read, w=write, x=execute)
|
||||
# └── file type (-=file, d=directory)
|
||||
|
||||
# Create a script
|
||||
# Step 3 — Create a script
|
||||
# ⚠️ Alpine uses ash, NOT bash! Use #!/bin/sh
|
||||
mkdir -p /root/lab/scripts
|
||||
echo '#!/bin/sh' > /root/lab/scripts/sayhello.sh
|
||||
echo 'echo "Hello from a script!"' >> /root/lab/scripts/sayhello.sh
|
||||
# 🔴 If you use #!/bin/bash it will say "not found"!
|
||||
|
||||
# Step 4 — Check permissions before making it executable
|
||||
ls -la /root/lab/scripts/sayhello.sh
|
||||
# Try to run it — should fail (no +x)
|
||||
./root/lab/scripts/sayhello.sh || echo "Failed! Need +x permission"
|
||||
|
||||
# Step 5 — Add execute permission
|
||||
chmod +x /root/lab/scripts/sayhello.sh
|
||||
ls -la /root/lab/scripts/sayhello.sh
|
||||
./root/lab/scripts/sayhello.sh
|
||||
|
||||
# Test permissions
|
||||
# Step 6 — Change permissions with numeric mode
|
||||
chmod 644 /root/lab/scripts/sayhello.sh
|
||||
ls -la /root/lab/scripts/sayhello.sh
|
||||
|
||||
# Step 7 — Remove execute permission
|
||||
chmod -x /root/lab/scripts/sayhello.sh
|
||||
./root/lab/scripts/sayhello.sh # What happens?
|
||||
./root/lab/scripts/sayhello.sh || echo "Permission denied!"
|
||||
|
||||
# Step 8 — Work with directories (need +x to enter)
|
||||
mkdir -p /root/lab/secret
|
||||
echo "classified" > /root/lab/secret/data.txt
|
||||
chmod 700 /root/lab/secret
|
||||
ls -la /root/lab/ | grep secret
|
||||
ls /root/lab/secret
|
||||
```
|
||||
|
||||
### 📝 Questions:
|
||||
1. What do the numbers `644`, `755`, and `+x` mean?
|
||||
2. What happens when you remove execute permission from a script?
|
||||
1. What does `ls -la` show? Describe each column.
|
||||
2. What does `+x`, `-x`, `644`, `755`, `700` mean?
|
||||
3. Why does a script need `+x` but `cat file.txt` doesn't?
|
||||
4. Why does a directory need `+x` to be accessible?
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user