Week 2: System Administration & Remote Access
Week 2: System Administration & Remote Access
Duration: 5 days (40 hours)
Goal: Manage systems and work with remote servers
Day 1-2: System Administration
Process Management
ps - List processes
1
2
3
4
5
$ ps aux
# Shows all running processes
$ ps aux | grep python
# Find Python processes
Understanding ps aux output:
1
2
3
4
5
6
7
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
rahul 1234 2.5 1.5 234567 45678 ? S 10:30 0:15 python app.py
│ │ │ │ │
│ │ │ └─ Memory % └─ Command
│ │ └─ CPU %
│ └─ Process ID
└─ Owner
top - Monitor processes live
1
2
3
4
$ top
# Press q to quit
# Press M to sort by memory
# Press P to sort by CPU
kill - Stop a process
1
2
3
4
5
6
7
8
9
10
11
12
# Find process
$ ps aux | grep myapp
rahul 5678 ... myapp
# Kill it
$ kill 5678
# Force kill if needed
$ kill -9 5678
# Kill by name
$ pkill myapp
Real-world example:
1
2
3
# Application hung
$ ps aux | grep "hung_app"
$ kill -9 1234
Using sudo
sudo - Run as administrator
1
2
3
4
5
6
$ apt update
# Permission denied
$ sudo apt update
[sudo] password: ****
# Works!
Common sudo commands:
1
2
3
4
$ sudo apt update # Update package list
$ sudo systemctl restart nginx # Restart service
$ sudo nano /etc/hosts # Edit system file
$ sudo su - # Become root (careful!)
Run previous command with sudo:
1
2
3
4
5
$ apt install nginx
# Permission denied
$ sudo !!
# Runs: sudo apt install nginx
System Information
df - Disk space
1
2
3
4
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 45G 51G 47% /
/dev/sda2 500G 234G 241G 50% /home
du - Directory size
1
2
3
4
5
6
7
$ du -sh /var/log
2.3G /var/log
$ du -sh *
500M Documents
1.2G Videos
345M Pictures
Find largest directories:
1
$ du -sh * | sort -hr | head -10
free - Memory usage
1
2
3
4
$ free -h
total used free shared buff/cache available
Mem: 7.7Gi 3.4Gi 1.2Gi 123Mi 3.1Gi 3.9Gi
Swap: 2.0Gi 0B 2.0Gi
uptime - System uptime
1
2
$ uptime
10:30:45 up 5 days, 2:15, 2 users, load average: 0.52, 0.48, 0.45
Package Management (Ubuntu)
apt - Install software
Update package list (do this first!):
1
$ sudo apt update
Install a package:
1
2
$ sudo apt install nginx
$ sudo apt install git curl wget
Remove a package:
1
2
$ sudo apt remove nginx
$ sudo apt autoremove # Clean up
Search for packages:
1
$ apt search python | grep python3
Upgrade all packages:
1
$ sudo apt update && sudo apt upgrade -y
Common packages:
1
2
3
4
$ sudo apt install build-essential # Compilers
$ sudo apt install python3 python3-pip
$ sudo apt install nodejs npm
$ sudo apt install git
Day 3: Archives & Compression
tar - Create and Extract Archives
Create compressed archive:
1
2
3
4
$ tar -czf backup.tar.gz folder/
# -c: create
# -z: compress with gzip
# -f: filename
Extract archive:
1
2
3
4
$ tar -xzf backup.tar.gz
# -x: extract
# -z: decompress
# -f: filename
Common patterns:
1
2
3
4
5
6
7
8
# Backup with date
$ tar -czf backup_$(date -I).tar.gz /important/data/
# Extract to specific location
$ tar -xzf archive.tar.gz -C /destination/
# View contents without extracting
$ tar -tzf archive.tar.gz
Remember: czf = Create Zip File, xzf = eXtract Zip File
zip - Alternative Archive Tool
Create zip:
1
$ zip -r archive.zip folder/
Extract zip:
1
$ unzip archive.zip
Real Backup Script
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
# Simple backup script
DATE=$(date -I)
BACKUP_DIR="/backup/$DATE"
mkdir -p "$BACKUP_DIR"
tar -czf "$BACKUP_DIR/documents.tar.gz" ~/Documents
tar -czf "$BACKUP_DIR/projects.tar.gz" ~/projects
echo "Backup complete: $BACKUP_DIR"
Day 4: SSH & Remote Access
Mac users: Follow the hands-on setup guide → Mac SSH & SCP Howto
SSH Basics
Connect to remote server:
1
2
3
4
5
$ ssh [email protected]
# Enter password when prompted
$ ssh [email protected]
# Can use IP address
Run single command:
1
$ ssh user@server "ls -la /var/log"
Exit connection:
1
2
$ exit
# Or press Ctrl+D
SSH Keys (No Password!)
1. Generate key (on your computer):
1
2
3
$ ssh-keygen -t rsa -b 4096
# Press Enter for default location
# Enter passphrase (or leave empty)
2. Copy key to server:
1
2
$ ssh-copy-id [email protected]
# Enter password one last time
3. Test - should connect without password:
1
2
$ ssh [email protected]
# No password prompt!
Connect with specific key:
1
2
3
4
5
$ ssh -i ~/.ssh/private_key [email protected]
# Use specific private key file
$ ssh -i /path/to/key.pem user@server
# Common for cloud servers (AWS, Azure)
SSH Config (Easy Connections)
Create ~/.ssh/config:
1
$ nano ~/.ssh/config
Add servers:
1
2
3
4
5
6
7
8
9
Host myserver
HostName example.com
User myusername
Port 22
Host prod
HostName prod.company.com
User deploy
IdentityFile ~/.ssh/prod_key
Now connect easily:
1
2
$ ssh myserver
# Instead of: ssh [email protected]
scp - Copy Files to/from Servers
Copy to server:
1
2
$ scp file.txt user@server:/home/user/
$ scp -r folder/ user@server:/home/user/
Copy from server:
1
2
$ scp user@server:/var/log/app.log ~/downloads/
$ scp -r user@server:/var/www/html ~/backup/
Use specific key:
1
2
$ scp -i ~/.ssh/private_key file.txt user@server:~/
$ scp -i /path/to/key.pem -r folder/ user@server:~/
Examples:
1
2
3
4
5
6
7
8
# Deploy website
$ scp -r website/ user@server:/var/www/html/
# Download logs
$ scp user@server:/var/log/app.log .
# Copy between home and server
$ scp ~/Documents/report.pdf user@server:~/
Day 5: Real-World Scenarios
Scenario 1: Deploy a Web Application
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 1. Connect to server
$ ssh user@webserver
# 2. Update system
$ sudo apt update && sudo apt upgrade -y
# 3. Install web server
$ sudo apt install nginx -y
# 4. Start it
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
# 5. Check it's running
$ sudo systemctl status nginx
# 6. Exit
$ exit
# 7. Upload website files
$ scp -r ~/mywebsite/* user@webserver:/var/www/html/
# 8. Set permissions
$ ssh user@webserver "sudo chown -R www-data:www-data /var/www/html"
# 9. Test
$ curl http://webserver
Scenario 2: Check Disk Space on Servers
1
2
3
4
5
6
7
8
9
10
#!/bin/bash
# check_disk.sh - Check disk space on multiple servers
SERVERS="server1.com server2.com server3.com"
for server in $SERVERS; do
echo "=== $server ==="
ssh user@$server "df -h | grep -v tmpfs"
echo ""
done
Scenario 3: Backup and Restore
Create backup:
1
2
$ tar -czf backup_$(date -I).tar.gz ~/important_data/
$ scp backup_$(date -I).tar.gz user@backup-server:~/backups/
Restore backup:
1
2
$ scp user@backup-server:~/backups/backup_2026-05-15.tar.gz .
$ tar -xzf backup_2026-05-15.tar.gz
Scenario 4: Monitor Logs for Errors
1
2
3
4
5
6
7
8
9
10
# Watch live logs
$ ssh user@server
$ sudo tail -f /var/log/syslog | grep -i error
# Count recent errors
$ ssh user@server "grep -i error /var/log/syslog | tail -100 | wc -l"
# Download logs for analysis
$ scp user@server:/var/log/syslog ./syslog.txt
$ grep -i "error" syslog.txt | less
Scenario 5: Quick System Check
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# system_check.sh - Quick health check
echo "=== Disk Space ==="
df -h | grep -v tmpfs
echo ""
echo "=== Memory ==="
free -h
echo ""
echo "=== Top Processes ==="
ps aux --sort=-%mem | head -10
echo ""
echo "=== System Uptime ==="
uptime
echo ""
echo "=== Recent Errors ==="
sudo tail -20 /var/log/syslog | grep -i error
Week 2 Exercises
Exercise 1: Process Management
1
2
3
4
5
6
# 1. Start a long-running process
$ sleep 300 &
# 2. Find it with ps
# 3. Check it in top
# 4. Kill it
Solution:
1
2
3
4
5
6
7
8
9
10
$ sleep 300 &
[1] 12345
$ ps aux | grep sleep
rahul 12345 ... sleep 300
$ kill 12345
$ ps aux | grep sleep
# Should be gone
Exercise 2: System Monitoring
1
2
3
4
# 1. Check disk space
# 2. Find your largest directory
# 3. Check available memory
# 4. See system uptime
Solution:
1
2
3
4
$ df -h
$ du -sh ~/* | sort -hr | head -5
$ free -h
$ uptime
Exercise 3: Create Automated Backup
1
2
3
4
# Create a script that:
# 1. Creates dated folder
# 2. Backs up Documents folder
# 3. Prints completion message
Solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
$ nano backup.sh
#!/bin/bash
DATE=$(date -I)
BACKUP_DIR="$HOME/backups/$DATE"
mkdir -p "$BACKUP_DIR"
tar -czf "$BACKUP_DIR/documents.tar.gz" ~/Documents
echo "Backup complete: $BACKUP_DIR/documents.tar.gz"
$ chmod +x backup.sh
$ ./backup.sh
Week 2 Quick Reference
Processes
1
2
3
4
5
ps aux # List all processes
ps aux | grep name # Find specific process
top # Monitor live
kill PID # Stop process
kill -9 PID # Force stop
System Info
1
2
3
4
df -h # Disk space
du -sh folder # Folder size
free -h # Memory usage
uptime # System uptime
Package Management
1
2
3
4
sudo apt update # Update package list
sudo apt install pkg # Install package
sudo apt remove pkg # Remove package
sudo apt upgrade # Upgrade all
Archives
1
2
3
4
tar -czf file.tar.gz dir/ # Create compressed archive
tar -xzf file.tar.gz # Extract archive
zip -r file.zip dir/ # Create zip
unzip file.zip # Extract zip
SSH
1
2
3
4
5
6
ssh user@server # Connect
ssh-keygen # Generate key
ssh-copy-id user@server # Copy key
scp file user@server:~/ # Copy to server
scp user@server:file ./ # Copy from server
exit # Disconnect
Course Complete!
Congratulations! You’ve completed Basic Linux Training.
What You’ve Learned
Week 1:
- Navigate Linux file system
- Manage files and directories
- View and edit text files
- Set permissions
- Search files and content
- Use pipes and redirection
Week 2:
- Manage processes
- Monitor system resources
- Install software
- Create backups
- Connect to remote servers
- Transfer files securely
Next Steps
Immediate (Today):
- Set up SSH keys for your work servers
- Create a backup script for your important files
- Add common servers to your SSH config
This Week:
- Use Linux commands daily
- Automate one repetitive task
- Set up your development environment in WSL
This Month:
- Learn basic shell scripting
- Explore tools specific to your role
- Help a colleague with Linux
Long Term:
- Consider full 200-hour program for depth
- Learn advanced scripting (bash, python)
- Get certified (LPIC-1, RHCSA)
Keep Learning
Resources:
man command- Best documentation- Stack Overflow - Search “ubuntu [your question]”
- Reddit r/linux4noobs - Friendly community
- Full 200-hour program - Comprehensive coverage
Practice Projects:
- Automate your backups
- Set up a personal web server
- Create deployment scripts
- Monitor multiple servers
- Build a log analysis tool
Final Checklist
- Can navigate any Linux system
- Can find and edit files
- Understand file permissions
- Can search logs for errors
- Can check system resources
- Can install software
- Can create backups
- Can SSH to servers
- Can transfer files securely
- Ready to use Linux daily at work
You’re now a functional Linux user. Keep practicing!