Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

修改 Linux SSH 預設埠 22 的兩種安全策略

編輯:Linux 教學

策略一:單一埠修改 + IP 限制

  1. 編輯 /etc/ssh/sshd_config,將 Port 22 改為自訂埠(避開常用埠)。
  2. 限制 SSH 登入 IP:
    • /etc/hosts.deny 加入 sshd:ALL
    • /etc/hosts.allow 加入 sshd:192.168.0.241(僅允許此 IP)
  3. 建議:伺服器不安裝 GNOME/KDE,精簡服務提高安全性。

策略二:雙埠過渡法(零停機風險)

  1. 編輯 /etc/ssh/sshd_config,保留 Port 22、新增 Port 50000。
  2. /etc/init.d/sshd restart,SSH 同時監聽 22 與 50000。
  3. 編輯防火牆 /etc/sysconfig/iptables 開放 50000,/etc/init.d/iptables restart。
  4. 用 SSH 工具測試連線 50000 埠。
  5. 測試成功後,移除 Port 22,再次重啟 sshd 與 iptables。
為何雙埠過渡?防止修改設定過程中斷線、斷網、誤操作導致無法遠端連線,必須跑機房處理。雙埠確保永遠有一條可用連線通道。
Copyright © Windows教程網 All Rights Reserved