Nabend,
ich möchte mich nach langer Zeit wieder mit einem VPS auseinandersetzen um nicht alles zu vergessen. Die Idee ist es eine Basis (nur Grundinstallation inkl. SSH, Fail2Ban und nftables) für eine "Docker Spielwiese" zu schaffen die ich bei Bedarf immer wieder herstellen kann falls was in die Hose geht. Zuerst wird das minimale Debian 11 Image installiert und ab gehts:
/etc/ssh/sshd_config (edit)
Danach wird ein SSH Keypaar generiert und mittels Passphrase geschützt. (Ich erlaube bewusst das Einloggen per root da ich nicht so Lust drauf habe immer den User wechseln zu müssen und mit Key (inkl. Passphrase) und anderem Port sollte ich doch einigermassen geschützt sein). Jetzt gehts nach der Installation von "fail2ban" und dem kopieren von "jail.conf" nach "jail.local" an die Konfiguration:
/etc/fail2ban/jail.local (edit)
bantime.increment = true
bantime.multipliers = 1 2 4 8 16 32 64
bantime = 3600
chain = input
banaction = nftables-multiport
[sshd]
enabled = true
port = 721
filter = sshd
logpath = /var/log/auth.log
maxretry = 1
backend = %(sshd_backend)s
Alles anzeigen
/etc/nftables/fail2ban.conf (edit)
#!/usr/sbin/nft -f
# Use ip as fail2ban doesn't support ipv6 yet
table ip fail2ban {
chain input {
# Assign a high priority to reject as fast as possible and avoid more complex rule evaluation
type filter hook input priority 100;
}
}
/etc/fail2ban/action.d/nftables-common.local (edit)
[Init]
# Definition of the table used
nftables_family = ip
nftables_table = fail2ban
# Drop packets
blocktype = drop
# Remove nftables prefix. Set names are limited to 15 char so we want them all
nftables_set_prefix =
/etc/fail2ban/jail.d/recidive.conf (edit)
# Jail for more extended banning of persistent abusers
# !!! WARNINGS !!!
# 1. Make sure that your loglevel specified in fail2ban.conf/.local
# is not at DEBUG level -- which might then cause fail2ban to fall into
# an infinite loop constantly feeding itself with non-informative lines
# 2. If you increase bantime, you must increase value of dbpurgeage
# to maintain entries for failed logins for sufficient amount of time.
# The default is defined in fail2ban.conf and you can override it in fail2ban.local
[recidive]
enabled = true
logpath = /var/log/fail2ban.log
banaction = nftables-allports
bantime = 86400 ; 1 day
findtime = 86400 ; 1 day
maxretry = 3
protocol = 0-255
Alles anzeigen
nach einem Reboot kann ich mich auch wie gewünscht nur per Key einloggen und gemäss "fail2ban-client status sshd" werden auch einzelne IPs bereits gebannt. Ist das als Basis so in Ordnung oder gibt es Sachen die ich ändern sollte / muss. Danke fürs Lesen