สำนักวิทยบริการและเทคโนโลยีสารสนเทศ (สวส.)

Office of Academic Resources and Information Technology

ปรับแต่ง Secure Shell (SSH) ให้ปลอดภัยมากขึ้น

ทำการการตรวจสอบ service sshd ว่ามีการ run อยู่หรือไม่ ด้วย command netstat ใน
[root@linux]# netstat -tanp|grep ssh
tcp 0 0 :::22 :::* LISTEN 2406/sshd

จากผลที่ได้จะเห็นว่า Server ใช้ port 22 ซึ่งเป็น port ค่า default ของ SSH ถือว่าไม่ปลอดภัย
ในการปรับแต่งค่า config ของ SSH ใน Linux Server นั้นทําได้โดยปรับแต่งที่ file sshd_config
ดังนี้
[root@linux]# vi /etc/ssh/sshd_config
#Port 22
Port 2222
( ค่าเดิมเป็น port 22 ทําการเปลี่ยนเป็น 54321 ควรมีอย่างน้อย 4 หลัก )
#Protocol 2,1
Protocol 2
( Protocol เลือกเป็น version 2 จะมีความปลอดภัยกว่า )
#ServerKeyBits 768
ServerKeyBits 1024
(เป็นคีย์ที่ใช้ในการเข้ารหัส ควรเปลี่ยนให้มากขึ้น )
#PermitRootLogin yes
PermitRootLogin no
( ไม่ควร ให้ user root login ได้ เพราะจะไม่รู้ว่า user ใดเข้ามาในระบบบ้าง
และเสี่ยงเกินไปที่ admin เข้ามาได้โดยตรง )
#MaxAuthTries 6
MaxAuthTries 3
( ใส่ password ผิดได้ไม่เกิน 3 ครั้ง )
#PasswordAuthentication yes
#PermitEmptyPasswords no
PermitEmptyPasswords no
(การใช้รหัสผ่านในการ log in และห้ามใช้รหัสผ่านที่ว่างเปล่า )
PasswordAuthentication yes (การใช้รหัสผ่านในการ log in และห้ามใช้รหัสผ่านที่ว่างเปล่า )


สั่ง restart service sshd
[root@linux]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@linux]#

ตรวจสอบ service sshd ว่า run อยู่หรือไม่และ port เปลี่ยนหรือไม่
[root@linux]# netstat -tanp|grep ssh
tcp 0 0 :::2222 :::* LISTEN 4447/sshd

ต่อไปเป็นการทดสอบโดยการ remote ด้วย SSH Client ในที่นี้จะใช้ OpenSSH ดังรูป จะต้องมีการ
กําหนด IP ของ Linux Server ,User ในการ login และ port ที่ใช้ในการ connect

ที่มา url : http://www.jodoi.com/article.html