改端口防的不是高手,是全网扫 22 的脚本小子,日志瞬间清净。
服务端
# /etc/ssh/sshd_config
Port 9120
UseDNS no
ClientAliveInterval 60
ClientAliveCountMax 3
sshd -t && systemctl restart ssh
ss -tlnp | grep 9120
fail2ban
/etc/fail2ban/jail.local:
[sshd]
enabled = true
port = 9120
maxretry = 5
bantime = 86400
findtime = 600
注意 port 必须和 sshd 一致,不然封错地方。
血泪教训
Ubuntu 24.04 默认 ssh.socket 激活,sshd_config 里改 Port 不生效,
还差点把自己锁外面。Debian 12 是经典 service 模式,改完 restart 就行。
动 SSH 前永远先 sshd -t,再开一个备用连接别断。