เปิด Multi Factor Authentication (MFA) ให้กับ OpenSSH บน Ubuntu 22.04
1. ติดตั้ง Google authenticator PAM module
sudo apt install libpam-google-authenticator
2. เปิดใช้งาน Google Authenticatior PAM ให้ OpenSSH
echo "auth required pam_google_authenticator.so" | sudo tee -a /etc/pam.d/sshd
sudo systemctl restart sshd.service
3. เปิด KbdInteractiveAuthentication
OpenSSH version 8.7 ขึ้นไปจะใช้ KbdInteractiveAuthentication แทน ChallengeResponseAuthentication
ตั้งค่า KbdInteractiveAuthentication yes
sudo grep -q "^KbdInteractiveAuthentication" /etc/ssh/sshd_config && sudo sed -i 's/^#?no/KbdInteractiveAuthentication yes/' /etc/ssh/sshd_config | sudo tee -a /etc/ssh/sshd_config >/dev/null <<<"KbdInteractiveAuthentication yes"
sudo systemctl restart sshd.service
4. เชื่อมต่อกับ Authenticator
ใช้คำสั่ง
google-authenticator
เปิด Authenticator บน Smart Phone (Google/Microsoft ก็ได้) จากนั้น Scan QR Code จากนั้นตอบตามนี้
Make tokens “time-base””: yes
Update the .google_authenticator file: yes
Disallow multiple uses: yes
Increase the original generation time limit: no
Enable rate-limiting: yes
เมื่อ ssh เข้ามา ก็จะได้หน้าจอประมาณนี้

หวังว่าจะเป็นประโยชน์ครับ
Leave a Reply