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

修改 SSH 默認端口 22 降低暴力破解風險

編輯:Linux 教學

修改 SSH 監聽端口是基礎安全加固措施,能有效避開自動化掃描腳本,減少日誌噪音與暴力破解嘗試。

修改配置文件

vi /etc/ssh/sshd_config
# 找到 #Port 22,取消註釋並修改為非常用端口(1024-65535)
Port 8284
# 建議保留 22 端口一段時間過渡,確認新端口正常後再刪除
# Port 22

重啟服務生效

systemctl restart sshd
# 或
service sshd restart

驗證新端口

# 查看監聽端口
netstat -antp | grep sshd
ss -antp | grep sshd

# 客戶端連接測試
ssh -p 8284 user@server_ip

防火牆同步開放

# firewalld (CentOS 7+)
firewall-cmd --permanent --add-port=8284/tcp
firewall-cmd --reload

# iptables
iptables -A INPUT -p tcp --dport 8284 -j ACCEPT
service iptables save

SELinux 環境下的端口標記

# 查看 SSH 端口上下文
semanage port -l | grep ssh_port_t
# 添加新端口
semanage port -a -t ssh_port_t -p tcp 8284

客戶端配置簡化連接

編輯 ~/.ssh/config:

Host myserver
    HostName server_ip
    User username
    Port 8284
    IdentityFile ~/.ssh/id_rsa

此後直接 ssh myserver 即可連接。

安全建議

  • 端口選擇 >1024 避免特權端口衝突
  • 避開常見替換端口 (2222, 222, 8022, 22222)
  • 必須配合密鑰認證、Fail2Ban、IP 白名單等措施
  • 修改端口非絕對安全,僅為「安全纵深」一層

總結

修改 /etc/ssh/sshd_config 中 Port 指令、重啟服務、同步防火牆/SELinux、更新客戶端配置,四步完成 SSH 端口遷移,顯著降低自動化攻擊面。

Copyright © Windows教程網 All Rights Reserved