Home > Blog > tech

สอน Linux System Administration ฉบับสมบูรณ์ 2026: จาก Zero สู่ SysAdmin มืออาชีพ

Linux System Administration 2026
2026-04-07 | tech | 3500 words

Linux เป็นระบบปฏิบัติการที่ขับเคลื่อนโครงสร้างพื้นฐานของอินเทอร์เน็ตทั้งหมด — เว็บเซิร์ฟเวอร์กว่า 96% ของโลกรันบน Linux, Cloud Computing ทั้ง AWS, Azure, GCP ใช้ Linux เป็นหลัก และ Supercomputer 100% ของโลกใช้ Linux ในปี 2026 ทักษะ Linux System Administration จึงเป็นทักษะที่มีคุณค่าสูงสุดสำหรับ IT Professional

บทความนี้จะพาคุณเรียนรู้ Linux SysAdmin ตั้งแต่พื้นฐานจนถึงระดับที่ใช้ดูแลเซิร์ฟเวอร์ Production ได้จริง ครอบคลุม File System, User Management, Networking, Services, Security, Automation และ Troubleshooting

เลือก Linux Distribution

DistroเหมาะกับPackage ManagerSupport
Ubuntu Serverมือใหม่, Cloud, Web Serverapt5 ปี (LTS)
Rocky LinuxEnterprise, แทน CentOSdnf/yum10 ปี
DebianServer ที่ต้องการ Stabilityapt5 ปี
AlmaLinuxEnterprise, RHEL-compatiblednf/yum10 ปี
Arch Linuxเรียนรู้ Linux deep, Cutting edgepacmanRolling
คำแนะนำ: เริ่มต้นด้วย Ubuntu Server 24.04 LTS เพราะมีเอกสารมากที่สุด Community ใหญ่ที่สุด และใช้ใน Cloud มากที่สุด

File System และ Directory Structure

Linux ใช้ Filesystem Hierarchy Standard (FHS) ที่มีโครงสร้างชัดเจน:

/              # Root — จุดเริ่มต้นของทุกอย่าง
├── /bin       # Binary — คำสั่งพื้นฐาน (ls, cp, mv)
├── /sbin      # System Binary — คำสั่งสำหรับ root (iptables, fdisk)
├── /etc       # Configuration — ไฟล์ตั้งค่าทั้งหมด
├── /home      # Home directories ของ users
├── /root      # Home directory ของ root
├── /var       # Variable data — logs, mail, spool
│   ├── /var/log    # System logs
│   ├── /var/www    # Web server files
│   └── /var/lib    # Application state
├── /tmp       # Temporary files
├── /usr       # User programs
│   ├── /usr/bin    # User binaries
│   ├── /usr/lib    # Libraries
│   └── /usr/share  # Shared data
├── /opt       # Optional/third-party software
├── /dev       # Device files
├── /proc      # Process information (virtual)
├── /sys       # System information (virtual)
└── /mnt       # Mount points

คำสั่งพื้นฐานที่ SysAdmin ต้องรู้

File Operations

# Navigation
pwd                    # ดู current directory
ls -la                 # ดูไฟล์ทั้งหมด (รวม hidden)
cd /var/log            # เปลี่ยน directory

# File Management
cp file.txt /backup/           # Copy
mv old.txt new.txt             # Move/Rename
rm -rf /tmp/old_logs/          # ลบ directory
mkdir -p /opt/myapp/config     # สร้าง directory (nested)

# Find Files
find / -name "*.conf" -type f          # หาไฟล์ตามชื่อ
find /var/log -mtime +30 -delete       # ลบไฟล์เก่ากว่า 30 วัน
locate nginx.conf                       # หาเร็ว (ใช้ database)

# File Content
cat /etc/hostname              # อ่านไฟล์
less /var/log/syslog           # อ่านไฟล์ยาว (scroll ได้)
head -20 access.log            # อ่าน 20 บรรทัดแรก
tail -f /var/log/syslog        # ดู log real-time
grep -r "error" /var/log/      # ค้นหา pattern ในไฟล์

Text Processing

# grep — ค้นหา pattern
grep -i "failed" /var/log/auth.log     # case-insensitive
grep -c "error" access.log              # นับจำนวน
grep -v "^#" /etc/nginx/nginx.conf      # ไม่รวม comments

# awk — ประมวลผล text
awk '{print $1}' access.log            # พิมพ์คอลัมน์แรก
awk '/error/ {print $0}' app.log       # เฉพาะบรรทัดที่มี error

# sed — แก้ไข text
sed -i 's/old/new/g' config.txt          # Replace ในไฟล์
sed -n '10,20p' file.txt                 # พิมพ์บรรทัด 10-20

# sort + uniq
sort access.log | uniq -c | sort -rn | head  # Top entries

# wc — นับ
wc -l /var/log/syslog                    # นับบรรทัด

User Management

# สร้าง User
sudo useradd -m -s /bin/bash -G sudo username
sudo passwd username

# แก้ไข User
sudo usermod -aG docker username    # เพิ่มเข้า group
sudo usermod -s /bin/zsh username   # เปลี่ยน shell

# ลบ User
sudo userdel -r username            # ลบพร้อม home directory

# จัดการ Group
sudo groupadd developers
sudo usermod -aG developers username

# ดูข้อมูล User
id username                          # ดู UID, GID, groups
who                                  # ใครล็อกอินอยู่
last                                 # ประวัติการล็อกอิน

File Permissions

# chmod — เปลี่ยน permission
chmod 755 script.sh        # rwxr-xr-x
chmod 644 config.txt       # rw-r--r--
chmod +x script.sh         # เพิ่ม execute
chmod -R 750 /opt/myapp    # Recursive

# chown — เปลี่ยน ownership
chown user:group file.txt
chown -R www-data:www-data /var/www

# Permission Numbers
# r=4, w=2, x=1
# 755 = rwxr-xr-x (owner:rwx, group:rx, others:rx)
# 644 = rw-r--r-- (owner:rw, group:r, others:r)
# 600 = rw------- (owner only)

Package Management

Ubuntu/Debian (apt)

sudo apt update                     # อัปเดต package list
sudo apt upgrade                    # อัปเกรด packages
sudo apt install nginx              # ติดตั้ง
sudo apt remove nginx               # ลบ
sudo apt autoremove                  # ลบ dependencies ที่ไม่ใช้
apt search keyword                   # ค้นหา package
apt show nginx                       # ดูข้อมูล package

Rocky/Alma/RHEL (dnf)

sudo dnf check-update               # ดู updates
sudo dnf update                      # อัปเกรด
sudo dnf install httpd               # ติดตั้ง
sudo dnf remove httpd                # ลบ
dnf search keyword                   # ค้นหา
dnf info httpd                       # ดูข้อมูล

Systemd — จัดการ Services

# จัดการ Service
sudo systemctl start nginx          # เริ่ม service
sudo systemctl stop nginx           # หยุด
sudo systemctl restart nginx        # รีสตาร์ท
sudo systemctl reload nginx         # โหลดค่าใหม่
sudo systemctl status nginx         # ดู status

# Enable/Disable (เริ่มตอน boot)
sudo systemctl enable nginx
sudo systemctl disable nginx

# ดู Services ทั้งหมด
systemctl list-units --type=service
systemctl list-units --state=failed  # ดูที่ล้มเหลว

# ดู Logs ด้วย journalctl
journalctl -u nginx                  # log ของ nginx
journalctl -u nginx --since "1 hour ago"
journalctl -f                        # follow ทุก service
journalctl -p err                    # เฉพาะ error

Networking

Network Configuration

# ดู IP Address
ip addr show
ip a                                 # ย่อ

# ดู Routing Table
ip route show

# ดู DNS
cat /etc/resolv.conf
resolvectl status

# ทดสอบ Connectivity
ping -c 4 google.com
traceroute google.com
dig example.com                      # DNS lookup
nslookup example.com

# ดู Port ที่เปิด
ss -tulnp                            # TCP/UDP listening ports
netstat -tulnp                       # แบบเก่า (ยังใช้ได้)

# ดาวน์โหลด
curl -O https://example.com/file
wget https://example.com/file

Firewall (UFW / firewalld)

# Ubuntu — UFW
sudo ufw enable
sudo ufw allow 22/tcp               # SSH
sudo ufw allow 80/tcp               # HTTP
sudo ufw allow 443/tcp              # HTTPS
sudo ufw deny 3306/tcp              # Block MySQL
sudo ufw status verbose

# Rocky/RHEL — firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

SSH — Secure Shell

# เชื่อมต่อ SSH
ssh user@server
ssh -p 2222 user@server              # custom port
ssh -i ~/.ssh/mykey.pem user@server   # ใช้ key

# SSH Key — ตั้งค่า (ปลอดภัยกว่า password)
ssh-keygen -t ed25519 -C "your@email.com"
ssh-copy-id user@server

# SSH Config (~/.ssh/config)
# Host myserver
#     HostName 192.168.1.100
#     User admin
#     Port 2222
#     IdentityFile ~/.ssh/mykey
# ใช้: ssh myserver

# SCP — Copy ไฟล์ผ่าน SSH
scp file.txt user@server:/tmp/
scp -r folder/ user@server:/opt/
scp user@server:/var/log/app.log ./

Harden SSH

# แก้ /etc/ssh/sshd_config
PermitRootLogin no           # ห้าม root login
PasswordAuthentication no    # ใช้ key only
Port 2222                    # เปลี่ยน port
MaxAuthTries 3               # จำกัดการลอง login
AllowUsers admin deploy      # อนุญาตเฉพาะ user ที่กำหนด

# รีสตาร์ท SSH
sudo systemctl restart sshd

Process Management

# ดู Processes
ps aux                               # ทั้งหมด
ps aux | grep nginx                  # ค้นหา
top                                  # Real-time monitor
htop                                 # สวยกว่า top

# จัดการ Process
kill PID                             # ส่ง SIGTERM
kill -9 PID                          # ส่ง SIGKILL (บังคับ)
killall nginx                        # kill ตามชื่อ

# Background/Foreground
command &                            # รัน background
nohup command &                      # รันต่อแม้ logout
jobs                                 # ดู background jobs
fg %1                                # เอากลับ foreground

# ดู Resource Usage
free -h                              # Memory
df -h                                # Disk
du -sh /var/log/*                    # ขนาด directory
iostat                               # Disk I/O
vmstat                               # Virtual memory

Log Management

# Log สำคัญ
/var/log/syslog          # System log (Ubuntu)
/var/log/messages        # System log (RHEL)
/var/log/auth.log        # Authentication log
/var/log/kern.log        # Kernel log
/var/log/nginx/          # Nginx logs
/var/log/apache2/        # Apache logs

# วิเคราะห์ Log
# หา Failed SSH Login
grep "Failed password" /var/log/auth.log | \
  awk '{print $11}' | sort | uniq -c | sort -rn | head

# Nginx Access Log — Top IPs
awk '{print $1}' /var/log/nginx/access.log | \
  sort | uniq -c | sort -rn | head -20

# Log Rotation
# ตั้งค่าใน /etc/logrotate.d/
cat /etc/logrotate.d/nginx

Cron Jobs — Scheduled Tasks

# แก้ไข Crontab
crontab -e

# Format: MIN HOUR DOM MON DOW COMMAND
# ตัวอย่าง:
0 2 * * * /opt/scripts/backup.sh     # ทุกวัน 02:00
*/5 * * * * /opt/scripts/check.sh    # ทุก 5 นาที
0 0 * * 0 /opt/scripts/weekly.sh     # ทุกวันอาทิตย์ 00:00
0 6,18 * * * /opt/scripts/sync.sh    # 06:00 และ 18:00

# ดู Crontab
crontab -l

# System Cron
ls /etc/cron.d/
ls /etc/cron.daily/
ls /etc/cron.weekly/

Storage Management

# ดู Disk
lsblk                                # ดู block devices
fdisk -l                             # ดู partitions
df -h                                # ดู mounted filesystems

# Mount/Unmount
sudo mount /dev/sdb1 /mnt/data
sudo umount /mnt/data

# Auto-mount (/etc/fstab)
# /dev/sdb1  /mnt/data  ext4  defaults  0  2

# LVM (Logical Volume Manager)
sudo pvdisplay                       # Physical volumes
sudo vgdisplay                       # Volume groups
sudo lvdisplay                       # Logical volumes

# Expand Filesystem
sudo lvextend -L +10G /dev/vg0/lv0
sudo resize2fs /dev/vg0/lv0

Security Hardening Checklist

  1. Update ทุกวัน: sudo apt update && sudo apt upgrade -y
  2. SSH Key Only: ปิด Password Authentication
  3. Firewall: เปิดเฉพาะ port ที่จำเป็น
  4. Fail2ban: ป้องกัน brute-force
  5. Non-root User: ไม่ใช้ root โดยตรง ใช้ sudo
  6. Audit Logs: ตั้ง auditd เพื่อตรวจสอบ
  7. Auto Updates: เปิด unattended-upgrades
  8. Disable Unused Services: ลด attack surface
  9. File Permissions: ตรวจสอบ sensitive files (600/640)
  10. Backup: ทำ backup ทุกวัน ทดสอบ restore เป็นประจำ

ติดตั้ง Fail2ban

sudo apt install fail2ban
sudo systemctl enable fail2ban

# ตั้งค่า /etc/fail2ban/jail.local
[sshd]
enabled = true
port = ssh
maxretry = 3
bantime = 3600
findtime = 600

Bash Scripting สำหรับ Automation

#!/bin/bash
# backup.sh — Daily Backup Script

BACKUP_DIR="/backup/$(date +%Y%m%d)"
LOG="/var/log/backup.log"

echo "$(date): Starting backup..." >> $LOG

# สร้าง directory
mkdir -p $BACKUP_DIR

# Backup database
mysqldump -u root mydb | gzip > "$BACKUP_DIR/db.sql.gz"

# Backup configs
tar czf "$BACKUP_DIR/etc.tar.gz" /etc/nginx /etc/php

# Backup web files
rsync -az /var/www/ "$BACKUP_DIR/www/"

# ลบ backup เก่ากว่า 30 วัน
find /backup -maxdepth 1 -type d -mtime +30 -exec rm -rf {} \;

echo "$(date): Backup complete" >> $LOG

เส้นทางอาชีพ Linux SysAdmin

ตำแหน่งเงินเดือน (ไทย)Certification
Junior SysAdmin20,000-35,000LPIC-1, CompTIA Linux+
System Administrator35,000-60,000LPIC-2, RHCSA
Senior SysAdmin50,000-90,000RHCE, LPIC-3
DevOps Engineer60,000-120,000CKA, AWS SA
Site Reliability Engineer80,000-180,000CKA + Cloud Certs

สรุป

Linux System Administration เป็นทักษะที่ทรงพลังและมีคุณค่าสูงสุดในโลก IT ไม่ว่าเทคโนโลยีจะเปลี่ยนไปอย่างไร — Cloud Computing, Container, Kubernetes, AI/ML — ทุกอย่างล้วนรันบน Linux ทั้งสิ้น

เริ่มต้นวันนี้: ติดตั้ง Ubuntu Server บน VirtualBox หรือสร้าง VPS บน Cloud (AWS Free Tier, DigitalOcean $4/เดือน) แล้วลองทำตามคำสั่งในบทความนี้ทีละขั้น การลงมือทำจริงคือวิธีเรียนรู้ Linux ที่ดีที่สุด


Back to Blog | iCafe Forex | SiamLanCard | Siam2R