4.2 KiB
4.2 KiB
🪴 Phase 1: Walking
Goal: Get comfortable with the Linux command line
🎯 Exercise 1 — Your First Commands
SSH into alpine-1 (through hop):
# Who am I?
whoami # → root
hostname # → localhost (or your hostname)
uname -a # Show full system info
uptime # How long since boot
# Where am I?
pwd # Print working directory
ls -la / # List root directory contents
# Make a file
echo "Hello from Phase 1!" > /root/hello.txt
ls -l /root/hello.txt # Check file details
cat /root/hello.txt # Read the file
Repeat on alpine-2 too!
✅ Verified by Midori
🎯 Exercise 2 — Navigation & File Basics
# Explore directories
ls /
ls /etc
ls /var
ls /home
# Create a directory structure
mkdir -p /root/lab/{notes,scripts,logs}
ls -R /root/lab
# Copy and move files
cp /root/hello.txt /root/lab/notes/
mv /root/hello.txt /root/lab/backup.txt
# Read system files
cat /etc/hostname
cat /etc/os-release
cat /etc/passwd
# Answer these:
echo $SHELL # What shell am I using?
wc -l /etc/passwd # How many users?
uname -r # Kernel version
📝 Questions to answer:
- What is your shell?
- How many users are listed in
/etc/passwd? - What kernel version are you running?
🎯 Exercise 3 — File Permissions
# Step 1 — Check current permissions
ls -la /root/lab/
# 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)
# 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
# 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 || 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:
- What does
ls -lashow? Describe each column. - What does
+x,-x,644,755,700mean? - Why does a script need
+xbutcat file.txtdoesn't? - Why does a directory need
+xto be accessible?
🎯 Exercise 4 — Text Editors
# Try nano (easier)
nano /root/lab/notes/my-notes.txt
# Type some text, Ctrl+O to save, Ctrl+X to exit
# Try vi (classic)
vi /root/lab/notes/vi-practice.txt
# Press 'i' to insert, type something
# Press Esc, then ':wq' to save and quit
💡 Key Lesson: Root bypasses everything!
- root can read/write/execute ANY file regardless of permissions
- Permissions only protect against non-root users
- Always use a regular user +
sudoin production! - Directories need
+xto be accessible
🔢 Permission Cheat Sheet
| Mode | Octal | Meaning |
|---|---|---|
rwx------ |
700 |
Only owner can do anything |
rwxr-xr-x |
755 |
Owner full, others read+execute |
rw-r--r-- |
644 |
Readable by all, writable by owner |
rw------- |
600 |
Only owner can read/write |
rw-rw-rw- |
666 |
Everyone can read/write (dangerous!) |
✅ Phase 1 Complete Checklist
- Exercise 1:
whoami,uname -a, file creation - Exercise 2: Directory structure,
cp,mv,cat - Exercise 3:
chmod, permissions understanding - ⏭️ Exercise 4: Skipped (already know text editors)
Next: Phase 2 - Networking 🌐