diff --git a/fail2ban.md b/fail2ban.md index 06efe987..aa6acf5b 100644 --- a/fail2ban.md +++ b/fail2ban.md @@ -1,57 +1,32 @@ # Fail2ban -For a number of reasons, an IP adresse may be wrongly blacklisted. If you wish to access your server through this specify IP you will need to unblock it. +Fail2Ban is an intrusion prevention software that protects computer servers from brute-force attacks. It monitors some log files and will ban IP addresses that shows brute-force-like behavior. -## IP unblock +In particular, Fail2ban monitors SSH connection attempts. After 5 failed login attempts on SSH, Fail2ban will ban the corresponding IP address from connecting through SSH for 10 minutes. If this IP is found to recidive several times, it might get ban for a week. -First, list all iptables rules with: `iptables -L --line-numbers` : +## Unban an IP + +To unban an IP from fail2ban, you first need to access your server by some mean (e.g. from another IP by the one being banned). + +Then look at fail2ban's log to identify in which jail the IP was put : ```bash -root@beudi:~# iptables -L --line-numbers -Chain INPUT (policy ACCEPT) -num target prot opt source destination -1 fail2ban-yunohost tcp -- anywhere anywhere multiport dports http,https -2 fail2ban-nginx tcp -- anywhere anywhere multiport dports http,https -3 fail2ban-dovecot tcp -- anywhere anywhere multiport dports smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s -4 fail2ban-sasl tcp -- anywhere anywhere multiport dports smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s -5 fail2ban-ssh tcp -- anywhere anywhere multiport dports ssh - -Chain FORWARD (policy ACCEPT) -num target prot opt source destination - -Chain OUTPUT (policy ACCEPT) -num target prot opt source destination - -Chain fail2ban-dovecot (1 references) -num target prot opt source destination -1 RETURN all -- anywhere anywhere - -Chain fail2ban-nginx (1 references) -num target prot opt source destination -1 RETURN all -- anywhere anywhere - -Chain fail2ban-sasl (1 references) -num target prot opt source destination -1 RETURN all -- anywhere anywhere - -Chain fail2ban-ssh (1 references) -num target prot opt source destination -1 RETURN all -- anywhere anywhere - -Chain fail2ban-yunohost (1 references) -num target prot opt source destination -1 DROP all -- 80.215.197.201 anywhere -2 RETURN all -- anywhere anywhere +$ tail /var/log/fail2ban.log +2019-01-07 16:24:47 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:49 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:51 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:54 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:57 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:57 fail2ban.actions [1837]: NOTICE [sshd] Ban 11.22.33.44 +2019-01-07 16:24:57 fail2ban.filter [1837]: NOTICE [recidive] Ban 11.22.33.44 ``` -Here, Ip adress `80.215.197.201` is banned in the `fail2ban-yunohost` rule. -To unblock: +Here, the IP `11.22.33.44` was banned in the `sshd` and `recidive` jails. + +Then unban the IP with the following commands : ```bash -iptables -D rule_name entry_number +$ fail2ban-client set sshd unbanip 11.22.33.44 +$ fail2ban-client set recidive unbanip 11.22.33.44 ``` -For intance: -```bash -iptables -D fail2ban-yunohost 1 -``` \ No newline at end of file diff --git a/fail2ban_fr.md b/fail2ban_fr.md index 8cad148e..cac68680 100644 --- a/fail2ban_fr.md +++ b/fail2ban_fr.md @@ -1,57 +1,32 @@ # Fail2ban -Pour diverses raisons, il peut arriver qu’une adresse IP ait été blacklistée. Si vous souhaitez accéder à votre serveur depuis cette IP, il faudra la débloquer. +Fail2Ban est un logiciel de prévention des intrusions qui protège les serveurs informatiques contre les attaques de brute-force. Il surveille certains journaux et bannira les adresses IP qui montrent un comportement de brute-forcing. -## Débloquer une IP +En particulier, Fail2ban surveille les tentatives de connexion SSH. Après 5 tentatives de connexion échouées sur SSH, Fail2ban banniera l'IP de se connecter via SSH pendant 10 minutes. Si cette adresse récidive plusieurs fois, elle peut être bannie pendant une semaine. -Tout d’abord on affiche le listing de toutes les règles iptables avec la commande `iptables -L --line-numbers` : +## Débannir une IP + +Pour débloquer une IP de fail2ban, vous devez d'abord accéder à votre serveur par un moyen quelconque (par exemple à partir d'une autre IP que celle bannie). + +Ensuite, regardez le journal de fail2ban pour identifier dans quelle 'prison' (jail) l'IP a été bannie : ```bash -root@beudi:~# iptables -L --line-numbers -Chain INPUT (policy ACCEPT) -num target prot opt source destination -1 fail2ban-yunohost tcp -- anywhere anywhere multiport dports http,https -2 fail2ban-nginx tcp -- anywhere anywhere multiport dports http,https -3 fail2ban-dovecot tcp -- anywhere anywhere multiport dports smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s -4 fail2ban-sasl tcp -- anywhere anywhere multiport dports smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s -5 fail2ban-ssh tcp -- anywhere anywhere multiport dports ssh - -Chain FORWARD (policy ACCEPT) -num target prot opt source destination - -Chain OUTPUT (policy ACCEPT) -num target prot opt source destination - -Chain fail2ban-dovecot (1 references) -num target prot opt source destination -1 RETURN all -- anywhere anywhere - -Chain fail2ban-nginx (1 references) -num target prot opt source destination -1 RETURN all -- anywhere anywhere - -Chain fail2ban-sasl (1 references) -num target prot opt source destination -1 RETURN all -- anywhere anywhere - -Chain fail2ban-ssh (1 references) -num target prot opt source destination -1 RETURN all -- anywhere anywhere - -Chain fail2ban-yunohost (1 references) -num target prot opt source destination -1 DROP all -- 80.215.197.201 anywhere -2 RETURN all -- anywhere anywhere +$ tail /var/log/fail2ban.log +2019-01-07 16:24:47 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:49 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:51 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:54 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:57 fail2ban.filter [1837]: INFO [sshd] Found 11.22.33.44 +2019-01-07 16:24:57 fail2ban.actions [1837]: NOTICE [sshd] Ban 11.22.33.44 +2019-01-07 16:24:57 fail2ban.filter [1837]: NOTICE [recidive] Ban 11.22.33.44 ``` -Il nous indique que l’IP `80.215.197.201` est bannie dans la règle `fail2ban-yunohost`. -Pour la débloquer : +Ici, l'IP `11.22.33.44` a été bannie dans les jails `sshd` et `recidive`. + +Puis débanissez l'IP avec les commandes suivantes : ```bash -iptables -D nom_de_la_regle numéro_de_l_entrée +$ fail2ban-client set sshd unbanip 11.22.33.44 +$ fail2ban-client set recidive unbanip 11.22.33.44 ``` -Par exemple : -```bash -iptables -D fail2ban-yunohost 1 -``` diff --git a/ssh.md b/ssh.md index b83e5a2a..a2425bcd 100644 --- a/ssh.md +++ b/ssh.md @@ -2,7 +2,7 @@ ## What's SSH? -**SSH** stands for Secure Shell, and refers to a protocol that allows to remotly control a machine using the command line interface (CLI). It is available by default on Linux and Mac OS / OSX. On Windows, unfortunately you might need to use the [PuTTy](http://www.fastcomet.com/tutorials/getting-started/putty) software. +**SSH** stands for Secure Shell, and refers to a protocol that allows to remotly control a machine using the command line interface (CLI). It is available by default in any terminal on Linux and Mac OS / OSX. On Windows, you may want to use [MobaXterm](https://mobaxterm.mobatek.net/download-home-edition.html) (after launching it, click on Session then SSH). ## During YunoHost installation @@ -14,7 +14,7 @@ If you are installing at home (e.g. on a Raspberry Pi or OLinuXino), then you ne - open a terminal and use `sudo arp-scan --local` to list the IP on your local network ; - use your internet box / router interface to list the machines connected, or check the logs ; -- plug a screen on your server, log in and type `ifconfig`. +- plug a screen on your server, log in and type `hostname --all-ip-address`. #### Connect @@ -26,15 +26,19 @@ ssh root@111.222.333.444 A password will be asked. If this is a VPS, your VPS provided should have communicated you the password. If you used a pre-installed image (for x86 computer or ARM board), the password should be `yunohost`. +