我的操作系统是 Ubuntu 20.04 LTS。
是否可以配置ufw limit
远程 ssh 的 -rule,以便仅限制失败的 ssh 连接尝试?现在它还限制成功的 ssh 连接,如果例如一个脚本调用另一个运行简短远程 ssh 任务的脚本,这会很烦人。这将导致脚本在某个时候失败。
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 13.59.50 +0300
Sat 29 Oct 2022 01:59:51 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 13.59.53 +0300
Sat 29 Oct 2022 01:59:53 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 13.59.54 +0300
Sat 29 Oct 2022 01:59:55 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 13.59.55 +0300
Sat 29 Oct 2022 01:59:56 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 13.59.56 +0300
Sat 29 Oct 2022 01:59:57 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 13.59.58 +0300
ssh: connect to host srvr02 port 12345: Connection refused
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 14.00.28 +0300
Sat 29 Oct 2022 02:00:29 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 14.00.30 +0300
Sat 29 Oct 2022 02:00:31 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 14.00.31 +0300
Sat 29 Oct 2022 02:00:32 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 14.00.33 +0300
Sat 29 Oct 2022 02:00:33 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 14.00.34 +0300
Sat 29 Oct 2022 02:00:34 PM EEST
jk@vm04:~/Documents$ date ; ssh jk@srvr02 -p 12345 date
Sat 29.10.2022 14.00.35 +0300
ssh: connect to host srvr02 port 12345: Connection refused
man ufw
关于限制:
ufw supports connection rate limiting, which is useful for protecting against brute-force
login attacks. When a limit rule is used, ufw will normally allow the connection but will
deny connections if an IP address attempts to initiate 6 or more connections within 30
seconds. See http://www.debian-administration.org/articles/187 for details. Typical usage
is:
ufw limit ssh/tcp
手册页上给出的链接已损坏。
相关的ufw规则是:
sudo ufw status
Status: active
To Action From
-- ------ ----
12345 LIMIT IN Anywhere (log) # ssh
当我将规则更改为:
12345 ALLOW Anywhere (log) # ssh
脚本运行时没有ssh: ... Connection refused
错误。
那么是否可以使用 ufw 设置和配置来仅限制失败的连接尝试而不是所有的连接尝试?
如果 ufw 不起作用,最好的选择是什么?也许是 fail2ban?