เว็บนี้มีลิงก์ affiliate — หากสมัครผ่านลิงก์ เราได้รับค่าคอมมิชชัน · Affiliate links. รายละเอียด

SSH คืออะไร ใช้งานอย่างไร คู่มือ SSH สำหรับผู้เริ่มต้น VPS และ Linux Server

SSH guide for beginners: what is SSH, how to connect from Windows/Mac/Linux, essential commands, SSH key setup.

SSH คืออะไร ใช้งานอย่างไร คู่มือ SSH สำหรับผู้เริ่มต้น VPS และ Linux Server
แนะนำAsiaGB.com — Web Hosting & VPS คุณภาพสูง พร้อมทีม Support ภาษาไทย 24 ชั่วโมง SSD NVMe uptime 99.9%

AsiaGB.com — Premium hosting & VPS with Thai support, NVMe SSD, 99.9% uptime.

เยี่ยมชม AsiaGB →

SSH คืออะไร

SSH (Secure Shell) คือ Protocol สำหรับเชื่อมต่อและควบคุม Server จากระยะไกลผ่าน Command Line อย่างปลอดภัย ใช้ Encryption เข้ารหัส Traffic ทั้งหมด ต่างจาก Telnet ที่ส่งข้อมูลแบบ Plain Text SSH เป็น Default สำหรับ VPS และ Cloud Server Linux ทุกเจ้า

SSH (Secure Shell) is a protocol for securely connecting to and controlling servers remotely via command line. It encrypts all traffic — unlike Telnet which sends data in plain text. SSH is the default access method for VPS and Linux cloud servers.

วิธีเชื่อมต่อ SSH

Command: ssh username@hostname หรือ ssh username@IP Port เป็น 22 by default ถ้าเปลี่ยน Port ใช้ -p เช่น ssh -p 2222 user@server ครั้งแรกจะถาม Fingerprint ให้พิมพ์ yes เพื่อ Trust เข้าสู่ Server

Command: ssh username@hostname or ssh username@IP — port 22 by default. If port changed, use -p: ssh -p 2222 user@server. First connection asks for fingerprint confirmation — type yes to trust.

SSH บน Windows

Windows 10/11 มี Built-in SSH Client แล้ว เปิด Command Prompt หรือ PowerShell แล้วพิมพ์ ssh user@server หรือใช้ PuTTY (ฟรี) สำหรับ GUI ที่บันทึก Session ได้ง่าย Windows Terminal + OpenSSH Client แนะนำสำหรับ Developer

Windows 10/11 has a built-in SSH client. Open Command Prompt or PowerShell and type ssh user@server. Or use PuTTY (free) for GUI that easily saves sessions. Windows Terminal + OpenSSH Client recommended for developers.

SSH บน Mac และ Linux

Mac และ Linux มี SSH Client ติดตั้งมาแล้ว เปิด Terminal แล้วพิมพ์ ssh user@server โดยตรง Mac Terminal, iTerm2, hoặือ Linux Gnome Terminal ทุกอันรองรับ SSH ไม่ต้องติดตั้งเพิ่ม

Mac and Linux have SSH client pre-installed. Open Terminal and type ssh user@server directly. Mac Terminal, iTerm2, or Linux Gnome Terminal all support SSH without any additional installation.

คำสั่ง SSH และ Linux พื้นฐาน

เมื่อเข้า Server แล้ว ใช้ Linux Command ควบคุม Server ls (List Files) cd (Change Directory) mkdir (สร้าง Folder) rm (ลบ) cp (Copy) mv (Move) cat (อ่านไฟล์) nano/vim (แก้ไขไฟล์) chmod (เปลี่ยน Permission) chown (เปลี่ยนเจ้าของ)

Once connected, use Linux commands: ls (list files), cd (change directory), mkdir (create folder), rm (delete), cp (copy), mv (move), cat (read file), nano/vim (edit file), chmod (change permission), chown (change owner).

SSH Key Authentication

SSH Key ปลอดภัยกว่า Password เพราะไม่มี Password ส่งผ่าน Network สร้าง Key: ssh-keygen -t ed25519 จะได้ ~/.ssh/id_ed25519 (Private Key) และ ~/.ssh/id_ed25519.pub (Public Key) Copy Public Key ไปวางบน Server: ssh-copy-id user@server

SSH Key is more secure than passwords because no password is transmitted over the network. Create key: ssh-keygen -t ed25519 gives ~/.ssh/id_ed25519 (private key) and ~/.ssh/id_ed25519.pub (public key). Copy public key to server: ssh-copy-id user@server.

ความปลอดภัย SSH

Disable Root Login: PermitRootLogin no ใน /etc/ssh/sshd_config ใช้ User แยก แล้ว sudo แทน ใช้ SSH Key แทน Password ปิด Password Authentication: PasswordAuthentication no ถ้าใช้ Key แล้ว ติดตั้ง Fail2Ban Block IP ที่ Login ผิดซ้ำ

Disable root login: PermitRootLogin no in /etc/ssh/sshd_config. Use a separate user with sudo instead. Use SSH Key instead of password. Disable password authentication: PasswordAuthentication no if using keys. Install Fail2Ban to block IPs with repeated failed logins.

เปลี่ยน Port SSH

Default Port 22 ถูก Scan บ่อยโดย Bot ถ้าเปลี่ยนเป็น Port อื่น (เช่น 2222) จะลด Noise ใน Log แก้ /etc/ssh/sshd_config เปลี่ยน Port 22 เป็น Port ใหม่ ต้อง Restart sshd และเปิด Port ใหม่ใน Firewall ก่อนปิด Session เดิม

Default port 22 is frequently scanned by bots. Changing to another port (e.g., 2222) reduces log noise. Edit /etc/ssh/sshd_config, change Port 22 to new port. Must restart sshd and open new port in firewall before closing current session.

SCP และ SFTP โอนไฟล์ผ่าน SSH

SCP (Secure Copy) ใช้โอนไฟล์ผ่าน SSH: scp file.txt user@server:/path/ SFTP คือ FTP บน SSH: sftp user@server FileZilla รองรับ SFTP Protocol สามารถใช้แทน FTP ได้ปลอดภัยกว่ามาก rsync ใช้ Sync ไฟล์ Directory ที่เปลี่ยนแปลงได้

SCP (Secure Copy) transfers files via SSH: scp file.txt user@server:/path/ SFTP is FTP over SSH: sftp user@server. FileZilla supports SFTP protocol — more secure than regular FTP. rsync syncs only changed files in a directory.

คำถามที่พบบ่อย (FAQ)

SSH กับ SFTP ต่างกันอย่างไร?
SSH คือ Protocol สำหรับเชื่อมต่อ Server ผ่าน Command Line SFTP (SSH File Transfer Protocol) คือ Subsystem ของ SSH ที่ใช้โอนไฟล์ โดยวิ่งบน Port 22 เหมือน SSH เลย FileZilla, WinSCP รองรับ SFTP เพื่อ Browse และ Transfer Files แบบ GUI
Root Login ผ่าน SSH อันตรายไหม?
อันตราย Bot จะ Brute Force user root@server ตลอดเวลา ควรปิด PermitRootLogin no แล้วใช้ User ปกติ + sudo แทน ถ้าต้องการทำอะไรใน Root Context บางอย่างสามารถทำได้ผ่าน sudo โดยที่ไม่ต้อง Login เป็น root โดยตรง
SSH Key Pair ทำงานอย่างไร?
SSH Key Pair ประกอบด้วย Private Key (เก็บในเครื่องเรา) และ Public Key (วางบน Server) เมื่อ Login Server จะส่ง Challenge มาให้ เราใช้ Private Key ตอบ ถ้า Public Key ตรงกัน Server ยืนยันตัวตนสำเร็จ ไม่มี Password ส่งผ่าน Network เลย
ถ้า Forget Root Password ทำอย่างไร?
VPS ส่วนใหญ่มี VNC Console หรือ Web Console ที่เข้าถึงได้โดยไม่ต้องใช้ SSH เข้า Console แล้ว Reset Password หรือ Boot เป็น Recovery Mode Cloud Provider เช่น DigitalOcean, AsiaGB มี Console ใน Dashboard ให้เข้าถึง Server ได้แม้ SSH ไม่ทำงาน