วิธีเพิ่มความปลอดภัยในการ Login เข้า Server สามารถทำได้โดยเพิ่ม Public key authentication สำหรับผู้ใช้งาน ด้วยวิธีนี้การการ login เข้าใช้งานจะต้องมีการใช้ Private Key ร่วมด้วย

ขั้นตอนการสร้าง SSH Key

1.Login เข้า Server ด้วย username ปกติ และเริ่มสร้าง SSH Key ด้วยคำสั่ง

ssh-keygen

2.จากนั้นระบบจะแจ้ง location ที่เก็บ key เรา enter ผ่านไป

Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):

3.Passphrase ก็ Enter ผ่านไป

Enter passphrase (empty for no passphrase):
Enter same passphrase again: 

4.จากนั้นเราจะได้ id___rsa และ id_rsa.pub เก็บไว้ที่ .ssh/

5.Copy Public Key จาก id___rsa.pub ไปที่ authorized_keys

cat .ssh/id_rsa.pub >> .ssh/authorized_keys

6.กำหนดสิทธิ์ให้ authorized_keys

chmod 600 .ssh/authorized_keys 
ขั้นตอนการ Login ด้วย SSH Key
ssh username@server -i privatekey 

หลังจากเพิ่ม SSH Key เข้าไปแล้ว เราควรจะเข้าไปตั้งค่า Disabling Password Authentication ใน SSH Daemon เพื่อไม่ให้ใช้ Password ต่อไป