Suggestion: Add fail2ban into core ASL3 image.
I just noticed lots of hacking attempts on my ASL3 Pi, from multiple miscreants. They use high numbered ports to bypass most firewalls, but still need to access ssh.
I happen to use a rather long and complicated password, so the odds are small they would ever crack my Pi, but… nothing is guaranteed…
Putting Fail2ban on the system takes less than 5 minutes. And if you, the ASL3 developers, do some script-smything it can be painless as you can either ask questions or just make default entires (see below).
Until then:
apt update
apt upgrade -y
apt install rsyslog
apt install fail2ban
Rsyslog will create additional logs, including auth.log which is needed for fail2ban to run. Additional logrotate entries will be created in /etc/logrotate.d.
Then edit the defaults-debian.conf and add or make sure these lines are there:
nano /etc/fail2ban/jail.d/defaults-debian.conf
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
# banaction will block the offending ip address from your machine, period for the given time based on bantime
# * `bantime`: The default value of 600 is set to ban an IP for a 10-minute duration. If set to a negative then the ban is permanment.
# change retries to your flavor, people do mistype.
# ignoreip should be your internal network. /24 is the entire class C address space xxx.xxx.xxx.1 - 254.
banaction = %(banaction_allports)s
maxretry = 3
bantime = 600
ignoreip = 192.168.1.0/24
Restart fail2ban:
systemctl restart fail2ban
Immediately my fail2ban log showed:
root@Allstar:/etc/fail2ban/jail.d# cat /var/log/fail2ban.log
2024-11-10 07:18:04,470 fail2ban.server [1813723]: INFO --------------------------------------------------
2024-11-10 07:18:04,470 fail2ban.server [1813723]: INFO Starting Fail2ban v1.0.2
2024-11-10 07:18:04,471 fail2ban.observer [1813723]: INFO Observer start…
2024-11-10 07:18:04,478 fail2ban.database [1813723]: INFO Connected to fail2ban persistent database ‘/var/lib/fail2ban/fail2ban.sqlite3’
2024-11-10 07:18:04,480 fail2ban.database [1813723]: WARNING New database created. Version ‘4’
2024-11-10 07:18:04,480 fail2ban.jail [1813723]: INFO Creating new jail ‘sshd’
2024-11-10 07:18:04,807 fail2ban.jail [1813723]: INFO Jail ‘sshd’ uses pyinotify {}
2024-11-10 07:18:04,808 fail2ban.jail [1813723]: INFO Initiated ‘pyinotify’ backend
2024-11-10 07:18:04,810 fail2ban.filter [1813723]: INFO maxLines: 1
2024-11-10 07:18:04,821 fail2ban.filter [1813723]: INFO maxRetry: 2
2024-11-10 07:18:04,822 fail2ban.filter [1813723]: INFO findtime: 600
2024-11-10 07:18:04,822 fail2ban.actions [1813723]: INFO banTime: 432000
2024-11-10 07:18:04,822 fail2ban.filter [1813723]: INFO encoding: UTF-8
2024-11-10 07:18:04,822 fail2ban.filter [1813723]: INFO Added logfile: ‘/var/log/auth.log’ (pos = 0, hash = 99518ecc17128336c6c4ba4e26c41405356122f4)
2024-11-10 07:18:04,824 fail2ban.jail [1813723]: INFO Jail ‘sshd’ started
2024-11-10 07:18:11,466 fail2ban.filter [1813723]: INFO [sshd] Found 152.53.32.62 - 2024-11-10 07:18:11
2024-11-10 07:18:52,046 fail2ban.filter [1813723]: INFO [sshd] Found 152.53.32.62 - 2024-11-10 07:18:51
2024-11-10 07:18:52,053 fail2ban.actions [1813723]: NOTICE [sshd] Ban 152.53.32.62
152.53.32.62, a German ip address is now banned for 10 minutes. Should the person (probably a bot) come back, it will be banned for another 10 minutes and so on.
Secondary Suggeston:
Change your sshd port from 22 to some other unused port number.
Add the new port to the firewall on the Pi and possibly your router if you want to log in when you are not connected to the internal network.
cd /etc/ssh
nano sshd_config
Change Port = 22 to another number
restart sshd
systemctl restart sshd
DO NOT LOG OUT OF YOUR CURRENT SSH SESSION UNTIL YOU TEST THE NEW CONFIGURATION!!
Open another ssh session and log in using a) the old port (you can't) and b) the new port (you should be successful).
Then delete from the firewall(s) the entry for ssh port 22.
You are now much more secure (nothing is guaranteed)