143 lines
3.6 KiB
Markdown
143 lines
3.6 KiB
Markdown
# 🪴 Phase 1: Walking
|
|
|
|
> Goal: Get comfortable with the Linux command line
|
|
|
|
---
|
|
|
|
## 🎯 Exercise 1 — Your First Commands
|
|
|
|
SSH into **alpine-1** (through hop):
|
|
```bash
|
|
# 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
|
|
|
|
```bash
|
|
# 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:
|
|
1. What is your shell?
|
|
2. How many users are listed in `/etc/passwd`?
|
|
3. What kernel version are you running?
|
|
|
|
---
|
|
|
|
## 🎯 Exercise 3 — File Permissions
|
|
|
|
```bash
|
|
# 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:
|
|
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?
|
|
|
|
---
|
|
|
|
## 🎯 Exercise 4 — Text Editors
|
|
|
|
```bash
|
|
# 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
|
|
```
|
|
|
|
---
|
|
|
|
## ✅ 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: Text editors (nano + vi)
|
|
|
|
**Next:** [[Phase 2 - Networking]] 🌐
|