SSH (Secure SHELL) เป็น Open-source และ Network Protocol ที่เชื่อถือได้มากที่สุด ใช้ Login Remote Servers เพื่อ Execute Commands และ Programs ยังใช้ Transfer Files ระหว่าง Computers ผ่าน Network ด้วย Secure Copy (SCP) และ Rsync Commands
[ You might also like: How to Secure and Harden OpenSSH Server ]
ในบทความนี้ จะแสดงวิธีตั้งค่า Password-less Login บน RHEL-based Linux Distributions เช่น CentOS, Fedora, Rocky Linux & AlmaLinux และ Debian-based เช่น Ubuntu & Mint ใช้ SSH Keys เชื่อม Remote Linux Servers โดยไม่ต้องใส่ Password
ใช้ Password-less Login ด้วย SSH Keys จะเพิ่ม Trust ระหว่าง 2 Linux Servers สำหรับ File Synchronization หรือ Transfer ง่ายขึ้น
My Setup Environment
SSH Client : 192.168.0.12 ( Fedora 34 ) SSH Remote Host : 192.168.0.11 ( CentOS 8 )
หากจัดการหลาย Linux Remote Servers SSH Password-less Login เป็นหนึ่งในวิธีดีที่สุด Automate Tasks เช่น Automatic Backups ด้วย Scripts, Synchronize Files ด้วย SCP Command, และ Remote Command Execution
[ You might also like: 25 Outstanding Backup Utilities for Linux Systems ]
ใน Example นี้ ตั้งค่า SSH Password-less Auto Login จาก Server 192.168.0.12 User tecmint ไป 192.168.0.11 User sheena
Step 1: สร้าง Authentication SSH-Keygen Keys บน (192.168.0.12)
Login เข้า Server 192.168.0.12 ด้วย User tecmint สร้าง Key Pair ด้วยคำสั่ง:
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/tecmint/.ssh/id_rsa): [Press enter key] Created directory '/home/tecmint/.ssh'. Enter passphrase (empty for no passphrase): [Press enter key] Enter same passphrase again: [Press enter key] Your identification has been saved in /home/tecmint/.ssh/id_rsa. Your public key has been saved in /home/tecmint/.ssh/id_rsa.pub. The key fingerprint is: 5f:ad:40:00:8a:d1:9b:99:b3:b0:f8:08:99:c3:ed:d3 admin@wsxdn.com The key's randomart image is: +--[ RSA 2048]----+ | ..oooE.++| | o. o.o | | .. . | | o . . o| | S . . + | | . . . o| | . o o ..| | + + | | +. | +-----------------+

Step 2: อัปโหลด SSH Key ไป (192.168.0.11)
ใช้ SSH จาก Server 192.168.0.12 อัปโหลด Public Key ใหม่ (id_rsa.pub) ไป Server 192.168.0.11 ภายใต้ sheena’s .ssh Directory ชื่อไฟล์ authorized_keys
$ ssh-copy-id admin@wsxdn.com
Step 3: ทดสอบ SSH Passwordless Login จาก 192.168.0.12
ตอนนี้ Login เข้า 192.168.0.11 เป็น sheena User จาก Server 192.168.0.12 เป็น tecmint User โดยไม่ต้อง Password
$ ssh admin@wsxdn.com

ในบทความนี้ คุณเรียนรู้การตั้งค่า SSH Passwordless Login ด้วย SSH Key หวังว่ากระบวนตรงไปตรงมา หากมีคำถาม Post ใน Comment Section ได้เลย