This blog post is more so a list of reminders for myself than anything else, but it will be helpful for anyone setting up their Raspberry Pi too. I did all of this on a Raspberry Pi 2 Model B.
Note: This blog post assumes you’ll be using a variant of the Raspbian OS. If
you’re using Fedora, Ubuntu, or another distro then some of these instructions
aren’t valid (
raspi-config will not be available for example) so YMMV.
Flashing an OS Image
- Download a Raspbian image from raspberrypi.org/downloads/raspbian/.
- Download balenaEtcher.
- Use balenaEtcher to load the image onto a microSD.
- Wait until balenaEtcheris finished.
- Eject the microSD from your PC or Laptop.
- Plug the microSD into the Raspberry Pi and boot it up with a keyboard and monitor attached.
Note: balenaEtcher is not strictly necessary, but it’s a nice and easy way to perform the flash.
Initial Login and Password Change
I might revisit this with steps to create a new user and delete the default
pi user, but will leave it as is for now.
- Wait until the Pi finishes booting and prompts for a login.
- Enter the username
- Enter the password
- Run the
passwdcommand once logged in and follow the prompts to create a new password.
Configure Internationalisation and Keyboard Layout
- Enter the
- Choose Localisation Options => Change Locale and set as required.
- Choose Localisation Options => Change Keyboard and choose your keyboard.
If your keyboard was not listed try this instead:
sudo vi /etc/default/keyboard.
- Change the value of
XKBLAYOUTto a valid code, e.g
I used a WiFi dongle to perform initial software installs and configuration since it’s easier. The WiFi adapter I use is the OURLiNK from adafruit) - it’s slow, but it gets the job done when you need a wireless option.
- Enter the
- Choose Network Options.
- Select the N2 Wi-fi option.
- Enter the network SSID.
- Enter the network password.
- Test connectivity by issuing a command, e.g
Enable SSH Access
- Enter the
- Select Interfacing Options => P2 SSH.
Yeswhen asked if you’d like SSH server to be enabled.
Add a Little Extra Security
sudo apt-get updateand
sudo apt-get install fail2ban.
ywhen prompted to perform the install.
sudo vi /etc/fail2ban/jail.localand paste content similar to the example below then run
sudo service fail2ban restart:
[ssh] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log banaction = iptables-allports bantime = 24h maxretry = 3 findtime = 30m
Verify SSH Access
Get the IP address of your Pi by issuing the
ifconfig command on the Pi. If
you’re using WiFi then the IP will be listed next to the
with a value such as
Using a Laptop/PC on the same network as your Pi try the following:
- Open a terminal.
- When prompted to continue connecting enter
- Enter the password for the
piuser when prompted.
- Run the commands
- Verify that the output from the
catcommands above show your SSH activity.
exitto quit the SSH session.
ssh firstname.lastname@example.org, but enter the wrong password a few times. You’ll get banned!
Switch to your Pi and check
/var/log/fail2ban.log to verify there’s an
[ssh] Ban 192.168.x.x entry. You can unban your PC/Laptop from the Pi
directly by issuing a
sudo fail2ban-client unban --all command.
You’re now ready to have some fun with your Pi.