Category Archives: Raspberry Pi

Prevent WordPress Brute-force attacks with fail2ban


If you run wordpress on a Raspberry Pi then the chances are very high that you get attacked with many attempts and failed logins on you wp-login.php file.

In my case all these attempt showed up in my websites statistics as uniq ip’s that have had many tousands hits on my site…’s not only a security problem, but it also have a small impact on performance of your site, i was lucky my Pi 3 didn’t complain and was fast enough 😉

You can use the filters and jails in this post on other linux distributions, but the fail2ban and log files may be in a different place, i have made this to work for the Pi 3 with Rasperian (Debian)

Setting up fail2ban jail and filter rules

I assume that you allready have installed fail2ban

Open the jail configuration

sudo vi /etc/fail2ban/jail.d/defaults-debian.conf

Put this section in the file and save

enabled = true
port = http,https
filter = wordpress
action = iptables-multiport[name=wordpress, port="http,https", protocol=tcp]
logpath = /var/log/apache2/*.log
maxretry = 30
findtime = 10800 ; 3 hours
bantime = 86400 ; 1 day

Make a filter file for wordpress

sudo vi /etc/fail2ban/filter.d/wordpress.conf

Make this section and save file.

failregex = ^<HOST> .* "POST .*wp-login.php
            ^<HOST> .* "POST .*xmlrpc.php
ignoreregex =

Restart fail2ban

sudo systemctl restart fail2ban

Raspberry Pi | how to disable swapping

If you wan’t to disable swapping on your raspberry pi to prevent fast weardown of you SD card or even if you are using a SSD to boot on via USB it can reduce your disks lifespan if you have swapping turned on and it’s default on.

Here is how to completely disable swapping on Raspberry Pi (raspberian)

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo update-rc.d dphys-swapfile remove
apt purge dphys-swapfile

This is tested on my Raspberry Pi 3 with Raspberian 9 (Debian 9 based)

WARNING: this is only a good idea if you know that the server has enough ram for it’s tasks.

Raspberry Pi | apt not working – segmentation fault

If you are experiencing segmentation fault on an apt update like this

peter@rasp1:~ $ sudo apt update
Get:1 jessie InRelease [22.9 kB]
Get:2 jessie InRelease [14.9 kB]
Get:3 jessie/main armhf Packages [9,536 kB]
Get:4 jessie/main armhf Packages [171 kB]
E: Method gzip has died unexpectedly!
E: Sub-process gzip received a segmentation fault.
E: Method /usr/lib/apt/methods/gzip did not start correctly

Then it can be resolved by sudo apt-get install –reinstall apt

peter@rasp1:~ $ sudo apt-get install --reinstall apt
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/1,067 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 38419 files and directories currently installed.)
Preparing to unpack .../apt_1. ...
Unpacking apt ( over ( ...
Processing triggers for man-db (2.7.5-1~bpo8+1) ...
Setting up apt ( ...
Processing triggers for libc-bin (2.19-18+deb8u10) ...

After update and reinstall you will be able to do an sudo apt-update end a sudo apt-upgrade

peter@rasp1:~ $ sudo apt update
Hit jessie InRelease
Hit jessie InRelease
Get:1 jessie/main armhf Packages [9,536 kB]
Get:2 jessie/main armhf Packages [171 kB]
Hit jessie/ui armhf Packages
Ign jessie/main Translation-en_GB
Ign jessie/main Translation-en
Ign jessie/ui Translation-en_GB
Get:3 jessie/contrib armhf Packages [43.3 kB]
Ign jessie/ui Translation-en
Get:4 jessie/non-free armhf Packages [84.2 kB]
Get:5 jessie/rpi armhf Packages [1,356 B]
Ign jessie/contrib Translation-en_GB
Ign jessie/contrib Translation-en
Ign jessie/main Translation-en_GB
Ign jessie/main Translation-en
Ign jessie/non-free Translation-en_GB
Ign jessie/non-free Translation-en
Ign jessie/rpi Translation-en_GB
Ign jessie/rpi Translation-en
Fetched 8,692 kB in 20s (417 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
49 packages can be upgraded. Run 'apt list --upgradable' to see them.

How to Boot Raspberry Pi from USB Hard Drive

Raspberry Pi’s normally boots from a SD/Micro SD card. That also means that your root and home partitions lives on the SD card and there is a lower limit to how big it can be and how fast it is compared to normal Hard Drives and SSD drives. Sometimes it can be better to move all other but the /boot partition to an external Hard Drive.

Here is how to move allready existing partitions to an external drive.

1. First fdisk the drive and create an EXT4 filesystem


fdisk /dev/sda
delete existing partitions
create new Primary Linux partition as /dev/sda1
write the system to disk with the command w
exit fdisk 


mke2fs -t ext4 /dev/sda1

2. Mount the External Harddrive on your Raspberry Pi

sudo su
mount -t ext4 /dev/sda1 /mnt

3. Install rsync

sudo apt-get install rsync

4. Copy all the files from the microSD card to the external hard drive. By using rsync then all file permissions and ownership are keept intact.

sudo rsync -axv / /mnt

this will take a while to finish.

5. Then we need to modify the Raspberry Pi’s startup file, Your device will look for it on the SDCard in the /boot partition

nano /boot/cmdline.txt

We need to edit two parts of this line. Change the root= to /dev/sda1, add rootdelay=5

It should look like this

6. Then we are adding the hard drive entry to “/mnt/etc/fstab” so the root folder in the external hard drive is automatically mounted at boot up.

nano /mnt/etc/fstab

Add this to the end of the file

/dev/sda1       /               ext4    defaults,noatime  0       1

Comment out the line with the SDCard with a # so it look like this

#PARTUUID=c1c4201a-01  /               ext4    defaults,noatime  0       1

After the changes, it should look like this (here is a screenshot from one of my Pi’s)

Reboot your Pi, and it should boot up and run from the external hard drive. One thing to note is that the microSD card needs to be in its slot, as the Pi needs to read the startup file from it before it boots up on the drive you wan’t

It is also possible to boot without the SDcard, but this way is how i prefer it to be done as it is very easy to switch back to the SDcard…just change the

Here is how the result can be with an External 1 TB USB Hard Drive.