Lab 3: Application Layer Protocols - File Transfer & Remote Access

ข้อมูลทั่วไป

รายการ รายละเอียด
วิชา ความปลอดภัยเครือข่าย (Network Security)
รูปแบบ ปฏิบัติการแบบจับคู่ (2 คน : 2 Laptops)

วัตถุประสงค์การเรียนรู้

เมื่อทำปฏิบัติการนี้เสร็จสิ้น นักศึกษาจะสามารถ:

  1. อธิบายความแตกต่างด้านความปลอดภัยระหว่าง FTP และ SFTP ได้
  2. สาธิตการดักจับข้อมูล FTP ที่ส่งแบบ Cleartext ได้
  3. ติดตั้งและกำหนดค่า SSH Server อย่างปลอดภัย
  4. สร้างและใช้งาน SSH Keys สำหรับการยืนยันตัวตน
  5. ใช้งาน SFTP และ SSHFS ในการถ่ายโอนไฟล์อย่างปลอดภัย
  6. เปรียบเทียบข้อดีข้อเสียของโปรโตคอลแต่ละประเภท

อุปกรณ์ที่ต้องเตรียม

ฮาร์ดแวร์

รายการ จำนวน หมายเหตุ
Laptop Computer 2 เครื่อง ติดตั้ง Linux (Ubuntu 22.04+) หรือใช้ Live USB
สาย LAN (Cat5e/Cat6) 1 เส้น สำหรับเชื่อมต่อโดยตรงระหว่าง 2 เครื่อง
หรือ WiFi Router 1 ตัว กรณีเชื่อมต่อผ่าน WiFi

การแบ่งบทบาท

เครื่อง บทบาท IP Address
Laptop A Server (ให้บริการ FTP, SSH, SFTP) 192.168.1.10
Laptop B Client (เชื่อมต่อและทดสอบ) 192.168.1.20

💡 หมายเหตุ: นักศึกษาควรสลับบทบาทกันทำในแต่ละส่วน เพื่อให้ได้ประสบการณ์ทั้งฝั่ง Server และ Client


การเตรียมความพร้อม (ทำก่อนเริ่ม Lab)

ขั้นตอนที่ 1: ติดตั้งซอฟต์แวร์ที่จำเป็น (ทั้ง 2 เครื่อง)

# อัปเดตระบบ
sudo apt update && sudo apt upgrade -y

# ติดตั้งแพ็คเกจที่จำเป็น
sudo apt install -y \
    openssh-server \
    openssh-client \
    vsftpd \
    sshfs \
    fuse3 \
    net-tools \
    tcpdump \
    wireshark \
    nmap \
    lftp

# เพิ่ม user เข้ากลุ่ม wireshark (เพื่อใช้งานโดยไม่ต้อง sudo)
sudo usermod -aG wireshark $USER

ขั้นตอนที่ 2: ตั้งค่า IP Address

วิธีที่ 1: เชื่อมต่อด้วยสาย LAN โดยตรง

บน Laptop A (Server):

# ตรวจสอบชื่อ interface
ip link show

# ตั้งค่า IP (สมมติ interface ชื่อ enp0s3 หรือ eth0)
sudo ip addr add 192.168.1.10/24 dev enp0s3
sudo ip link set enp0s3 up

# หรือใช้ nmcli (NetworkManager)
sudo nmcli con add type ethernet con-name "Lab-Connection" \
    ifname enp0s3 ip4 192.168.1.10/24
sudo nmcli con up "Lab-Connection"

บน Laptop B (Client):

sudo ip addr add 192.168.1.20/24 dev enp0s3
sudo ip link set enp0s3 up

# หรือใช้ nmcli
sudo nmcli con add type ethernet con-name "Lab-Connection" \
    ifname enp0s3 ip4 192.168.1.20/24
sudo nmcli con up "Lab-Connection"

วิธีที่ 2: เชื่อมต่อผ่าน WiFi Router

ขั้นตอนที่ 3: ทดสอบการเชื่อมต่อ

# จาก Laptop A ping ไปยัง Laptop B
ping -c 3 192.168.1.20

# จาก Laptop B ping ไปยัง Laptop A
ping -c 3 192.168.1.10

ขั้นตอนที่ 4: สร้าง User สำหรับทดสอบ (บน Laptop A - Server)

# สร้างผู้ใช้ทดสอบ
sudo useradd -m -s /bin/bash labuser
sudo passwd labuser
# ตั้งรหัสผ่านเป็น: Lab@123

# สร้างไฟล์ทดสอบ
sudo -u labuser bash -c 'echo "=== Secret File ===" > /home/labuser/secret.txt'
sudo -u labuser bash -c 'echo "Username: admin" >> /home/labuser/secret.txt'
sudo -u labuser bash -c 'echo "Password: P@ssw0rd123!" >> /home/labuser/secret.txt'
sudo -u labuser bash -c 'echo "Credit Card: 4111-1111-1111-1111" >> /home/labuser/secret.txt'

# สร้างไฟล์ทดสอบขนาดต่างๆ
sudo -u labuser bash -c 'dd if=/dev/urandom of=/home/labuser/test_1mb.bin bs=1M count=1 2>/dev/null'
sudo -u labuser bash -c 'echo "This is a public file" > /home/labuser/public.txt'

# ตรวจสอบไฟล์
ls -la /home/labuser/

ส่วนที่ 1: FTP และความเสี่ยงด้านความปลอดภัย (45 นาที)

🎯 วัตถุประสงค์

1.1 ติดตั้งและตั้งค่า FTP Server

📍 บน Laptop A (Server):

# ตรวจสอบว่า vsftpd ติดตั้งแล้ว
sudo systemctl status vsftpd

# สำรองไฟล์ config เดิม
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.backup

# แก้ไขไฟล์ config
sudo nano /etc/vsftpd.conf

แก้ไขหรือเพิ่มค่าต่อไปนี้:

# === vsftpd.conf สำหรับทดสอบ ===

# การตั้งค่าพื้นฐาน
listen=YES
listen_ipv6=NO

# อนุญาต local users
anonymous_enable=NO
local_enable=YES
write_enable=YES

# ตั้งค่า chroot
chroot_local_user=YES
allow_writeable_chroot=YES

# Passive mode (สำคัญสำหรับการเชื่อมต่อผ่าน firewall)
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100
pasv_address=192.168.1.10

# เปิด logging
xferlog_enable=YES
xferlog_std_format=NO
log_ftp_protocol=YES
vsftpd_log_file=/var/log/vsftpd.log

บันทึกและรีสตาร์ท:

# รีสตาร์ท service
sudo systemctl restart vsftpd
sudo systemctl status vsftpd

# ตรวจสอบว่า port 21 เปิดอยู่
sudo ss -tlnp | grep :21

# ปิด firewall ชั่วคราว (สำหรับการทดสอบ)
sudo ufw disable
# หรือเปิด port ที่ต้องการ
# sudo ufw allow 21/tcp
# sudo ufw allow 40000:40100/tcp

1.2 ทดสอบการเชื่อมต่อ FTP

📍 บน Laptop B (Client):

# เชื่อมต่อ FTP Server
ftp 192.168.1.10

ในหน้าต่าง FTP ให้ทำตามลำดับ:

Connected to 192.168.1.10.
220 (vsFTPd 3.0.5)
Name (192.168.1.10:student): labuser
331 Please specify the password.
Password: Lab@123
230 Login successful.

ftp> pwd
257 "/home/labuser" is the current directory

ftp> ls
200 PORT command successful.
150 Here comes the directory listing.
-rw-r--r--    1 1001     1001           95 Jan 29 10:00 secret.txt
-rw-r--r--    1 1001     1001      1048576 Jan 29 10:00 test_1mb.bin
-rw-r--r--    1 1001     1001           22 Jan 29 10:00 public.txt
226 Directory send OK.

ftp> get secret.txt
200 PORT command successful.
150 Opening BINARY mode data connection for secret.txt (95 bytes).
226 Transfer complete.
95 bytes received in 0.00 secs

ftp> bye
221 Goodbye.
# ตรวจสอบไฟล์ที่ดาวน์โหลด
cat secret.txt

1.3 🔴 การดักจับข้อมูล FTP (สำคัญมาก!)

⚠️ คำเตือน: การดักจับ network traffic ต้องทำในเครือข่ายที่ได้รับอนุญาตเท่านั้น

📍 บน Laptop A (Server) - เปิด Terminal ใหม่:

# เริ่มดักจับ traffic บน port 21 (FTP)
sudo tcpdump -i any port 21 -A -n

📍 บน Laptop B (Client) - เปิด Terminal ใหม่:

# เชื่อมต่อ FTP อีกครั้ง (ขณะที่ tcpdump กำลังทำงาน)
ftp 192.168.1.10

# Login ด้วย labuser / Lab@123
# แล้วดาวน์โหลดไฟล์ secret.txt

📍 สังเกตผลลัพธ์บน Laptop A:

# ตัวอย่างผลลัพธ์ที่จะเห็น:

10:15:23.123456 IP 192.168.1.20.54321 > 192.168.1.10.21: 
    ... USER labuser ...

10:15:23.234567 IP 192.168.1.20.54321 > 192.168.1.10.21: 
    ... PASS Lab@123 ...

10:15:24.345678 IP 192.168.1.10.21 > 192.168.1.20.54321: 
    ... 230 Login successful ...

❗ สิ่งที่ต้องสังเกต:

1.4 บันทึก Traffic เป็นไฟล์และวิเคราะห์

📍 บน Laptop A (Server):

# บันทึก traffic เป็นไฟล์ pcap
sudo tcpdump -i any port 21 -w /tmp/ftp_capture.pcap &

# จดบันทึก PID
echo $!

📍 บน Laptop B (Client):

# เชื่อมต่อ FTP และทำกิจกรรมต่างๆ
ftp 192.168.1.10
# login, list, get file, quit

📍 บน Laptop A (Server):

# หยุด tcpdump
sudo pkill tcpdump

# วิเคราะห์ไฟล์ที่บันทึก
sudo tcpdump -r /tmp/ftp_capture.pcap -A | grep -E "(USER|PASS|secret)"

# หรือเปิดด้วย Wireshark
wireshark /tmp/ftp_capture.pcap &

ใน Wireshark:

  1. ใช้ Filter: ftp
  2. คลิกขวาที่ packet > Follow > TCP Stream
  3. จะเห็น username และ password แบบชัดเจน

1.5 📝 แบบฝึกหัดส่วนที่ 1

คำถามที่ 1.1: จากการดักจับ traffic คุณพบข้อมูลอะไรบ้างที่ถูกส่งแบบ Cleartext?

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

คำถามที่ 1.2: ถ้ามีผู้ไม่หวังดี (Attacker) อยู่ในเครือข่ายเดียวกัน เขาสามารถทำอะไรได้บ้าง?

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

คำถามที่ 1.3: FTP เหมาะสำหรับการใช้งานในสถานการณ์ใด? ไม่เหมาะสำหรับสถานการณ์ใด?

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

ส่วนที่ 2: SSH - Secure Shell (45 นาที)

🎯 วัตถุประสงค์

2.1 ตรวจสอบและเริ่มต้น SSH Server

📍 บน Laptop A (Server):

# ตรวจสอบสถานะ SSH Server
sudo systemctl status ssh

# เริ่ม SSH Server (ถ้ายังไม่ทำงาน)
sudo systemctl start ssh
sudo systemctl enable ssh

# ตรวจสอบว่า port 22 เปิดอยู่
sudo ss -tlnp | grep :22

2.2 ทดสอบการเชื่อมต่อด้วย Password

📍 บน Laptop B (Client):

# เชื่อมต่อ SSH ด้วย password
ssh labuser@192.168.1.10

# ครั้งแรกจะถาม host key fingerprint
# พิมพ์ yes เพื่อยืนยัน
# ใส่รหัสผ่าน: Lab@123

# หลังจาก login สำเร็จ
whoami
pwd
ls -la

# ออกจาก session
exit

2.3 สร้าง SSH Key Pair

📍 บน Laptop B (Client):

# สร้าง ED25519 key (แนะนำ - ปลอดภัยและเร็ว)
ssh-keygen -t ed25519 -C "student@laptop-b" -f ~/.ssh/id_lab

# จะถาม passphrase - ใส่หรือเว้นว่างก็ได้
# แนะนำให้ใส่ passphrase เพื่อความปลอดภัย เช่น: MyKey@123

# ตรวจสอบ key ที่สร้าง
ls -la ~/.ssh/

# ดู public key
cat ~/.ssh/id_lab.pub

# ดู fingerprint ของ key
ssh-keygen -l -f ~/.ssh/id_lab.pub

ผลลัพธ์ที่ควรได้:

-rw-------  1 student student  411 Jan 29 10:30 id_lab
-rw-r--r--  1 student student   98 Jan 29 10:30 id_lab.pub

2.4 คัดลอก Public Key ไปยัง Server

📍 บน Laptop B (Client):

วิธีที่ 1: ใช้ ssh-copy-id (แนะนำ)

ssh-copy-id -i ~/.ssh/id_lab.pub labuser@192.168.1.10

# ใส่รหัสผ่านของ labuser: Lab@123

วิธีที่ 2: คัดลอกด้วยตนเอง

# แสดง public key
cat ~/.ssh/id_lab.pub

# คัดลอก output ทั้งหมด (เริ่มจาก ssh-ed25519 ...)

📍 บน Laptop A (Server):

# Login เป็น labuser
sudo su - labuser

# สร้าง directory .ssh
mkdir -p ~/.ssh
chmod 700 ~/.ssh

# เพิ่ม public key (วางจากที่ copy มา)
echo "ssh-ed25519 AAAA... student@laptop-b" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

# ตรวจสอบ
cat ~/.ssh/authorized_keys
exit

2.5 ทดสอบการเชื่อมต่อด้วย Key

📍 บน Laptop B (Client):

# เชื่อมต่อโดยใช้ key
ssh -i ~/.ssh/id_lab labuser@192.168.1.10

# ถ้าตั้ง passphrase ไว้ จะถาม passphrase ของ key (ไม่ใช่ password ของ server)
# ถ้าไม่ได้ตั้ง จะเข้าได้เลยโดยไม่ถามอะไร

# ทดสอบว่า login สำเร็จ
whoami
exit

2.6 ดักจับ SSH Traffic (เปรียบเทียบกับ FTP)

📍 บน Laptop A (Server) - Terminal ใหม่:

# ดักจับ traffic บน port 22
sudo tcpdump -i any port 22 -A -n -c 50

📍 บน Laptop B (Client):

# เชื่อมต่อ SSH
ssh -i ~/.ssh/id_lab labuser@192.168.1.10

# ทำกิจกรรมบางอย่าง
cat secret.txt
exit

📍 สังเกตผลลัพธ์บน Laptop A:

# ผลลัพธ์จะเป็นข้อมูลที่ถูกเข้ารหัส เช่น:
10:45:12.123456 IP 192.168.1.20.54321 > 192.168.1.10.22:
    ...SSH-2.0-OpenSSH_8.9p1...
    
10:45:12.234567 IP 192.168.1.10.22 > 192.168.1.20.54321:
    ...@#$%^&*()_+{}|:"<>?...  (encrypted data)

❗ สิ่งที่ต้องสังเกต:

2.7 กำหนดค่า SSH Server ให้ปลอดภัยยิ่งขึ้น

📍 บน Laptop A (Server):

# สำรองไฟล์ config
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup

# แก้ไขไฟล์ config
sudo nano /etc/ssh/sshd_config

เพิ่มหรือแก้ไขค่าต่อไปนี้:

# === sshd_config - Secure Configuration ===

# Port (อาจเปลี่ยนเพื่อลดการถูก scan)
Port 22

# ปิด root login
PermitRootLogin no

# ปิด password authentication (ใช้ key เท่านั้น)
PasswordAuthentication no
PubkeyAuthentication yes

# จำกัดจำนวนครั้งที่ login ผิดพลาด
MaxAuthTries 3

# ตั้ง timeout
ClientAliveInterval 300
ClientAliveCountMax 2

# จำกัดผู้ใช้ที่สามารถ SSH ได้
AllowUsers labuser

# ปิด features ที่ไม่จำเป็น
X11Forwarding no
AllowTcpForwarding no
PermitEmptyPasswords no

# เปิด logging
LogLevel VERBOSE
# ตรวจสอบ syntax
sudo sshd -t

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

2.8 ทดสอบ SSH ที่กำหนดค่าแล้ว

📍 บน Laptop B (Client):

# ทดสอบเชื่อมต่อด้วย key (ควรสำเร็จ)
ssh -i ~/.ssh/id_lab labuser@192.168.1.10
exit

# ทดสอบเชื่อมต่อด้วย password (ควรไม่สำเร็จ)
ssh -o PubkeyAuthentication=no labuser@192.168.1.10
# จะได้: Permission denied (publickey)

# ทดสอบเชื่อมต่อด้วย user อื่น (ควรไม่สำเร็จ)
ssh -i ~/.ssh/id_lab root@192.168.1.10
# จะได้: Permission denied

2.9 📝 แบบฝึกหัดส่วนที่ 2

คำถามที่ 2.1: เปรียบเทียบผลลัพธ์จากการดักจับ traffic ของ FTP และ SSH

หัวข้อ FTP SSH
Username ? ?
Password ? ?
เนื้อหาไฟล์ ? ?
สรุป ? ?

คำถามที่ 2.2: ทำไมควรปิด PasswordAuthentication และใช้ PubkeyAuthentication แทน?

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

คำถามที่ 2.3: SSH Key มีประเภทอะไรบ้าง? ปัจจุบันแนะนำให้ใช้ประเภทใด? เพราะเหตุใด?

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

ส่วนที่ 3: SFTP - SSH File Transfer Protocol (30 นาที)

🎯 วัตถุประสงค์

3.1 การใช้งาน SFTP

📍 บน Laptop B (Client):

# เชื่อมต่อ SFTP
sftp -i ~/.ssh/id_lab labuser@192.168.1.10

คำสั่งพื้นฐานใน SFTP:

sftp> help                    # แสดงความช่วยเหลือ
sftp> pwd                     # แสดง remote directory
sftp> lpwd                    # แสดง local directory
sftp> ls -la                  # list ไฟล์บน remote
sftp> lls -la                 # list ไฟล์บน local

# ดาวน์โหลดไฟล์
sftp> get secret.txt
sftp> get test_1mb.bin downloaded_test.bin

# อัปโหลดไฟล์
sftp> !echo "Uploaded from client" > /tmp/upload_test.txt
sftp> lcd /tmp
sftp> put upload_test.txt

# จัดการ directory
sftp> mkdir new_folder
sftp> cd new_folder
sftp> pwd

# ออกจาก session
sftp> bye

3.2 ดักจับ SFTP Traffic

📍 บน Laptop A (Server) - Terminal ใหม่:

# ดักจับ traffic บน port 22 (SFTP ใช้ port เดียวกับ SSH)
sudo tcpdump -i any port 22 -A -n -c 30

📍 บน Laptop B (Client):

# เชื่อมต่อ SFTP และดาวน์โหลดไฟล์
sftp -i ~/.ssh/id_lab labuser@192.168.1.10 <<< "get secret.txt"

❗ สังเกต: Traffic ทั้งหมดถูกเข้ารหัส เหมือน SSH!

3.3 SFTP Batch Mode

📍 บน Laptop B (Client):

# สร้างไฟล์คำสั่ง batch
cat > /tmp/sftp_commands.txt << 'EOF'
pwd
ls -la
get secret.txt /tmp/secret_batch.txt
get public.txt /tmp/public_batch.txt
bye
EOF

# รัน batch mode
sftp -i ~/.ssh/id_lab -b /tmp/sftp_commands.txt labuser@192.168.1.10

# ตรวจสอบไฟล์ที่ดาวน์โหลด
ls -la /tmp/*.txt

3.4 เปรียบเทียบ FTP vs SFTP

📍 บน Laptop B (Client):

# สร้างไฟล์ทดสอบขนาด 10 MB
dd if=/dev/urandom of=/tmp/test_10mb.bin bs=1M count=10

# === ทดสอบ FTP ===
time ftp -n 192.168.1.10 << EOF
user labuser Lab@123
binary
put /tmp/test_10mb.bin test_ftp.bin
bye
EOF

# === ทดสอบ SFTP ===
time sftp -i ~/.ssh/id_lab labuser@192.168.1.10 << EOF
put /tmp/test_10mb.bin test_sftp.bin
bye
EOF

3.5 📝 แบบฝึกหัดส่วนที่ 3

คำถามที่ 3.1: SFTP ใช้ port อะไร? เหมือนหรือต่างจาก FTP?

คำตอบ:
__________________________________________________________________

คำถามที่ 3.2: ข้อดีของ SFTP เทียบกับ FTP มีอะไรบ้าง?

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

คำถามที่ 3.3: บันทึกเวลาที่ใช้ในการถ่ายโอนไฟล์ 10 MB

โปรโตคอล เวลาที่ใช้ หมายเหตุ
FTP ? วินาที
SFTP ? วินาที

ส่วนที่ 4: SSHFS - SSH Filesystem (30 นาที)

🎯 วัตถุประสงค์

4.1 ติดตั้ง SSHFS

📍 บน Laptop B (Client):

# ตรวจสอบการติดตั้ง
sshfs --version

# ถ้ายังไม่ติดตั้ง
sudo apt install sshfs fuse3 -y

# เพิ่ม user เข้า fuse group (ถ้าจำเป็น)
sudo usermod -aG fuse $USER
# ต้อง logout แล้ว login ใหม่ หรือใช้ newgrp fuse

4.2 Mount Remote Filesystem

📍 บน Laptop B (Client):

# สร้าง mount point
mkdir -p ~/remote_server

# Mount remote filesystem
sshfs -o IdentityFile=~/.ssh/id_lab \
      labuser@192.168.1.10:/home/labuser \
      ~/remote_server

# ตรวจสอบการ mount
df -h | grep remote_server
mount | grep sshfs

# เข้าถึงไฟล์เหมือน local directory!
ls -la ~/remote_server/
cat ~/remote_server/secret.txt

4.3 ทำงานกับไฟล์ผ่าน SSHFS

📍 บน Laptop B (Client):

# อ่านไฟล์
cat ~/remote_server/public.txt

# สร้างไฟล์ใหม่
echo "Created via SSHFS from Laptop B" > ~/remote_server/sshfs_created.txt

# แก้ไขไฟล์
echo "Appended text" >> ~/remote_server/public.txt

# สร้าง directory
mkdir ~/remote_server/new_folder

# คัดลอกไฟล์จาก local ไป remote
cp /tmp/test_10mb.bin ~/remote_server/copied_via_sshfs.bin

# ตรวจสอบ
ls -la ~/remote_server/

📍 บน Laptop A (Server) - ตรวจสอบว่าไฟล์ถูกสร้างจริง:

ls -la /home/labuser/
cat /home/labuser/sshfs_created.txt

4.4 Mount พร้อม Options ที่แนะนำ

📍 บน Laptop B (Client):

# Unmount ก่อน
fusermount -u ~/remote_server

# Mount พร้อม options เพิ่มเติม
sshfs -o IdentityFile=~/.ssh/id_lab \
      -o reconnect \
      -o ServerAliveInterval=15 \
      -o ServerAliveCountMax=3 \
      -o cache=yes \
      -o kernel_cache \
      labuser@192.168.1.10:/home/labuser \
      ~/remote_server

# อธิบาย options:
# reconnect           : เชื่อมต่อใหม่อัตโนมัติเมื่อขาดการเชื่อมต่อ
# ServerAliveInterval : ส่ง keepalive ทุก 15 วินาที
# cache=yes           : เปิด caching เพื่อเพิ่มความเร็ว
# kernel_cache        : ใช้ kernel page cache

4.5 Unmount

📍 บน Laptop B (Client):

# Unmount แบบปกติ
fusermount -u ~/remote_server

# ตรวจสอบว่า unmount แล้ว
mount | grep sshfs
ls ~/remote_server/    # ควรว่างเปล่า

# ถ้า busy ให้ใช้ lazy unmount
# fusermount -uz ~/remote_server

4.6 ทดสอบความเร็ว SSHFS

📍 บน Laptop B (Client):

# Mount อีกครั้ง
sshfs -o IdentityFile=~/.ssh/id_lab \
      labuser@192.168.1.10:/home/labuser \
      ~/remote_server

# ทดสอบเขียนไฟล์ผ่าน SSHFS
time dd if=/dev/urandom of=~/remote_server/speed_test.bin bs=1M count=20

# ทดสอบอ่านไฟล์ผ่าน SSHFS
time dd if=~/remote_server/speed_test.bin of=/dev/null bs=1M

# เปรียบเทียบกับ SCP
time scp -i ~/.ssh/id_lab /tmp/test_10mb.bin labuser@192.168.1.10:/home/labuser/scp_test.bin

# Unmount
fusermount -u ~/remote_server

4.7 📝 แบบฝึกหัดส่วนที่ 4

คำถามที่ 4.1: SSHFS ใช้โปรโตคอลอะไรในการถ่ายโอนข้อมูล?

คำตอบ:
__________________________________________________________________

คำถามที่ 4.2: ข้อดีของ SSHFS คืออะไร?

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

คำถามที่ 4.3: SSHFS เหมาะกับการใช้งานแบบใด? ไม่เหมาะกับการใช้งานแบบใด?

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

ส่วนที่ 5: สรุปและเปรียบเทียบ (15 นาที)

5.1 ตารางเปรียบเทียบโปรโตคอล

คุณสมบัติ FTP SFTP SSH SSHFS
Port 21 (+ data port) 22 22 22
เข้ารหัส ❌ ไม่ ✅ ใช่ ✅ ใช่ ✅ ใช่
ดักจับ Password ได้ ✅ ได้ ❌ ไม่ได้ ❌ ไม่ได้ ❌ ไม่ได้
ดักจับไฟล์ได้ ✅ ได้ ❌ ไม่ได้ - ❌ ไม่ได้
ใช้ SSH Key ได้ ❌ ไม่ได้ ✅ ได้ ✅ ได้ ✅ ได้
Firewall friendly ❌ (หลาย port) ✅ (port เดียว)
การใช้งาน ถ่ายโอนไฟล์ ถ่ายโอนไฟล์ Remote shell Mount filesystem

5.2 แผนภูมิการเลือกใช้

ต้องการทำอะไร?
│
├─► ถ่ายโอนไฟล์ครั้งเดียว
│   │
│   ├─► ต้องการความปลอดภัย ──► ใช้ SFTP หรือ SCP
│   │
│   └─► ไม่สนใจความปลอดภัย ──► ใช้ FTP (ไม่แนะนำ!)
│       (เครือข่ายภายในที่ปิด)
│
├─► ทำงานกับไฟล์ remote บ่อยๆ ──► ใช้ SSHFS
│
└─► เข้าถึง shell ของ server ──► ใช้ SSH

5.3 📝 แบบทดสอบท้าย Lab

1. จากการทดลอง อธิบายความแตกต่างที่คุณสังเกตได้ระหว่างการดักจับ traffic ของ FTP และ SSH/SFTP

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

2. เขียนคำสั่งสำหรับ:

# สร้าง key:
__________________________________________________________________

# คัดลอก public key:
__________________________________________________________________

# เชื่อมต่อ SFTP:
__________________________________________________________________

3. บริษัทของคุณต้องการให้พนักงานสามารถถ่ายโอนไฟล์ไปยัง server ได้อย่างปลอดภัย จงเสนอแนวทางการตั้งค่าที่เหมาะสม พร้อมอธิบายเหตุผล

คำตอบ:
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________

🔧 การคืนค่า Configuration

บน Laptop A (Server) - หลังเสร็จสิ้น Lab:

# คืนค่า vsftpd.conf
sudo cp /etc/vsftpd.conf.backup /etc/vsftpd.conf
sudo systemctl restart vsftpd

# คืนค่า sshd_config
sudo cp /etc/ssh/sshd_config.backup /etc/ssh/sshd_config
sudo systemctl restart ssh

# ลบ user ทดสอบ (ถ้าต้องการ)
sudo userdel -r labuser

# เปิด firewall กลับ (ถ้าปิดไว้)
sudo ufw enable