Server 1st Steps: Unterschied zwischen den Versionen
Zeile 38: | Zeile 38: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | == Fail2Ban == | ||
+ | Mit Fail2Ban kann der SSH Zugang zusätzlich abgesichert werden. | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | sudo apt install fail2ban | ||
+ | |||
+ | sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local | ||
+ | |||
+ | sudo nano /etc/fail2ban/jail.local | ||
+ | |||
+ | [...] | ||
+ | [DEFAULT] | ||
+ | |||
+ | # | ||
+ | # MISCELLANEOUS OPTIONS | ||
+ | # | ||
+ | |||
+ | # "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not | ||
+ | # ban a host which matches an address in this list. Several addresses can be | ||
+ | # defined using space (and/or comma) separator. | ||
+ | ignoreip = 192.168.0.0/24 | ||
+ | |||
+ | # External command that will take an tagged arguments to ignore, e.g. <ip>, | ||
+ | # and return true if the IP is to be ignored. False otherwise. | ||
+ | # | ||
+ | # ignorecommand = /path/to/command <ip> | ||
+ | ignorecommand = | ||
+ | |||
+ | # "bantime" is the number of seconds that a host is banned. | ||
+ | bantime = 1h | ||
+ | |||
+ | # A host is banned if it has generated "maxretry" during the last "findtime" | ||
+ | # seconds. | ||
+ | findtime = 10min | ||
+ | |||
+ | # "maxretry" is the number of failures before a host get banned. | ||
+ | maxretry = 5 | ||
+ | |||
+ | [...] | ||
+ | |||
+ | # | ||
+ | # SSH servers | ||
+ | # | ||
+ | |||
+ | [sshd] | ||
+ | |||
+ | enabled = true | ||
+ | port = ssh | ||
+ | filter = sshd | ||
+ | logpath = /var/log/auth.log | ||
+ | maxretry = 4 | ||
+ | |||
+ | [...] | ||
+ | |||
+ | sudo systemctl restart fail2ban.service | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
==Laufwerke überwachen== | ==Laufwerke überwachen== |
Version vom 13. November 2018, 20:36 Uhr
Auf dieser Seite werden Tools, Scripts und Konfigurationseinstellungen aufgelistet, welche den Server absichern.
Inhaltsverzeichnis
Apticron
Apticron benachrichtigt den Administrator über verfügbare Updates per eMail. Hierzu wird Postfix verwendet.
sudo apt-get install postfix libsasl2-modules bsd-mailx
sudo apt-get install apticron
#Konfiguration
sudo dpkg-reconfigure apticron
Benachrichtigung bei SSH Login
Mit Hilfe von S-Nail und einem Script wird der Admin bei jedem Anmeldeversuch per SSH per eMail benachrichtigt.
sudo apt install s-nail
sudo nano /opt/shell-login.sh
#!/bin/bash
echo "Login auf $(hostname) am $(date +%Y-%m-%d) um $(date +%H:%M)"
echo "Benutzer: $USER"
echo
pinky
sudo nano /etc/profile
#Zeile anhängen
/opt/shell-login.sh | mailx -s "Betreff" mail@adress.com
sudo chmod 755 /opt/shell-login.sh
Fail2Ban
Mit Fail2Ban kann der SSH Zugang zusätzlich abgesichert werden.
sudo apt install fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
[...]
[DEFAULT]
#
# MISCELLANEOUS OPTIONS
#
# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space (and/or comma) separator.
ignoreip = 192.168.0.0/24
# External command that will take an tagged arguments to ignore, e.g. <ip>,
# and return true if the IP is to be ignored. False otherwise.
#
# ignorecommand = /path/to/command <ip>
ignorecommand =
# "bantime" is the number of seconds that a host is banned.
bantime = 1h
# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime = 10min
# "maxretry" is the number of failures before a host get banned.
maxretry = 5
[...]
#
# SSH servers
#
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 4
[...]
sudo systemctl restart fail2ban.service
Laufwerke überwachen
Mit Hilfe von smartmontools werden die Laufwerke überwacht und der Admin per eMail über Fehler informiert.
sudo apt install smartmontools
sudo nano /etc/default/smartmontools
start_smartd=yes
sudo nano /etc/smartd.conf
/dev/sda -d ata -n standby -a -I 194 -W 6,50,55 -R 5 -M daily -M test -m servernews@mail.de
/dev/sdb -d ata -n standby -a -I 194 -W 6,50,55 -R 5 -M daily -M test -m servernews@mail.de
/dev/sdc -d ata -n standby -a -I 194 -W 6,50,55 -R 5 -M daily -M test -m servernews@mail.de
/dev/sdd -d ata -n standby -a -I 194 -W 6,50,55 -R 5 -M daily -M test -m servernews@mail.de
/dev/sde -d ata -n standby -a -I 194 -W 6,50,55 -R 5 -M daily -M test -m servernews@mail.de
sudo smartd -q onecheck
IP Tables
Mit Hilfe von iptables wird der IP-Paketfilter des Linuxkernels konfiguriert. Mit Hilfe von iptables-persitent werden die erstellten Regeln automatisch gespeichert.
sudo apt-get install iptables
sudo apt-get install iptables-persistent
Zunächst wird mit folgendem Befehl verhindert, dass die aktuellen SSH-Sessions geschlossen werden.
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
Im Nachfolgenden werden die Filteregeln erstellt und den sogenannten Chains hinzugefügt. Der erste Befehl erlaubt den Zugriff von der lokalen IP Adresse 192.168.0.50 aus. Der zweite Befehl erlaubt die IP-Adressen von 192.168.0.1 bis 192.168.0.254.
sudo iptables -A INPUT -s 192.168.0.50 -p tcp --dport 28100 -j ACCEPT
sudo iptables -A INPUT -s 192.168.0.0/24 -p tcp --dport 28100 -j ACCEPT
Mit Hilfe des Befehls "iptables -L" werden alle Chains und die dazugehörigen Filterregeln aufgelistet. Diese werden anschließen gespeichert, damit sie beim nächsten Reboot nicht erneut geladen werden müssen.
sudo iptables -L
sudo bash -c "iptables-save > /etc/iptables/rules.v4"
sudo bash -c "iptables-save > /etc/iptables/rules.v6"