# Overview I currently have 4 Raspberry Pi's which are in various states of *hardening* which I need to finish. I will outline the steps to harden a Raspberry Pi. These steps can also be followed to harden any system running Linux. | Device Name | Device Type | Operating System | Notes | | ------------ | --------------------- | ---------------- | ----------- | | `rpi5-node1` | Raspberry Pi 5 (4GB) | Raspbian | Cluster | | `rpi5-node2` | Raspberry Pi 5 (4GB) | Raspbian | Cluster | | `rpi4-node3` | Raspberry Pi 4B (4GB) | Rasspbian | Cluster | | `rpi4-node4` | Raspberry Pi 4B (4GB) | Raspbian | Remote Node | I like the Raspberry Pi's and decided to stick with a few. Once I get these one's up and running, I may likely purchase more. I like the idea of what can be achieved with **single board computers (SBC)** and **microcontrollers** which I purchased my first **Arduino Uno R4** and will be messing around with that more. ## Add Node to Tailscale Tailscale allows me to access my nodes securely and remotely wherever I may be. Tailscale uses a mesh, so the devices do not go to a central exit node, they connect point-to-point with each other. To install Tailscale via SSH: 1. Login to Raspberry Pi via `ssh` 2. Run the following command to install **Tailscale**: ```bash sudo curl https://tailscale.com/install.sh | sh ``` 3. When installation is complete, ensure **Tailscale** is running: ```bash sudo tailscale up ``` - This ensures the service is running. - Run the following command to verify it is operating: ```bash tailscale status ``` I ensure that **Tailscale** is on all of my nodes in the **homelab**. ### Benefits of Tailscale for the Homelab **Remote Access**: If I am outside of my Local Area Network I can still remote into my nodes. **Status Check**: When I need to quickly see if a node is up, I can just run `tailscale status`. --- ## System Updates Ensure the Operating System is up to date. ```bash sudo apt update && sudo apt upgrade -y sudo apt install unattended-upgrades -y sudo dpkg-reconfigure --priority=low unattended-upgrades ``` **unattended-upgrades** automatically installs security updates in the background. --- ## SSH Configuration - Remove Password Authentication - Disable Root Login - Disable X11 (Video Graphics) - Limit MaxAuthTries **Why**: - Remove Password Authentication: Using **ED25519** encryption keys removes the need to login remotely using a password. Disabling logging in via password reduces an attack surface. - Disable Root Login: Forces the use of `sudo` - removes an attack surface for attackers to escalate privileges. - Disable X11: Since using `ssh` to remote into the nodes, there is no need to send graphics over via ssh. - Limit MaxAuthTries: Reduce from 6 to 3. Reduces amount of times an attack can try to guess password. 1. Open SSH Configuration: ```bash sudo nano /etc/ssh/sshd_config ``` 2. MaxAuthTries - Un-comment `MaxAuthTries` - Change from 6 to 3 3. PasswordAuthentication - Un-comment `PasswordAuthentication` - Change from `yes` to `no` 4. X11Forwarding - Un-comment if it's not already - Change from `yes` to `no` 5. PermitRootLogin - Un-comment `PermitRootLogin` - Change to `no` **Note**: Instead of doing this for all nodes. I do believe we can just copy this over since all nodes are running `Raspbian OS` When finished press `CTRL-o` (keep file name the same!) and then `CTRL-x` to exit `nano`. ### [OPTIONAL]: Run Cron Job to Check for Updates on SSH Server 1. Run the Crontab Editor: ```bash sudo crontab -e # Edit cron jobs ``` 2. Put this in the editor: ```plaintext 0 5 * * * apt install openssh-server ``` ## Linux should now check for an update every day at 5 AM. ## Firewall - Uncomplicated Firewall (UFW) ```bash sudo apt install ufw sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow in on tailscale0 # allow all Tailscale traffic sudo ufw allow 22/tcp # or your SSH port sudo ufw enable ``` 1. `sudo apt install ufw` - Installed Uncomplicated Firewall. 2. `sudo ufw default deny incoming`- Deny all incoming traffic by default. Closing down ports. 3. `sudo ufw default allow outgoing` - Allow all outgoing traffic by default. The Pi can communicate with other nodes and services. 4. `sudo ufw allow in tailscale01` - Allow all Tailscale traffic. 5. `sudo ufw allow 22/tcp` - Allow Port 22 for TCP 6. `sudo ufw enable` - Enable the firewall. Ensure that Port 22 and Tailscale are allowed before enabling so there is no lockout. Firewall should now be active. --- ## Fail2Ban Even though key-only authorization is enabled. It's a good idea to ensure Fail2Ban is running. After installation, **Fail2Ban** should run automatically. Check by using the following command: ```bash sudo systemctl status fail2ban ``` If it is not running, enable it: ```bash sudo systemctl enable fail2ban ``` Then start it: ```bash sudo systemctl start fail2ban ``` > [!note] Check Status Check status again before running `start`. Still learning so may be unnecessary. ## Disable Unused Services Check: ```bash sudo systemctl list-units --type=service --status=running ``` This will return all running services. Check to see if there are services which are unnecessary for your lab, such as Bluetooth. The purposes of this is to reduce as many attack surfaces as possible for an intruder into your network. Check for default `pi` user: ```bash cat /etc/passwd # Lists all users on system. Some users are service users. ``` ```bash cat /etc/passwd | grep pi # Check to see if user pi exists. ``` ## Conclusion The node (Raspberry Pi) should now be locked down pretty well. I'm sure there are additional lock-downs which can be done. If there are multiple nodes, ensure to do this for all nodes. One lesson I've learned by going through this process a handful of times is that this is why Infrastructure-as-Code (IaC) is popular. This isn't particularly hard to do, but it can become tedious and prone to mistakes. The **Raspberry Pi** is a great device (for me at least) to learn **Linux** and **Hardware** and **Networking** and **Security** in a cost-effective manner. ## Resources - [Raspberry Pi Documentation](https://www.raspberrypi.com/documentation/) - [Raspberry Pi Configuration](https://www.raspberrypi.com/documentation/computers/configuration.html) - Configuring SSH - [Raspberry Pi - Introduction to Remote Access](https://www.raspberrypi.com/documentation/computers/remote-access.html#introduction-to-remote-access) - [Raspberry Pi - Operational Security](https://www.raspberrypi.com/documentation/computers/configuration.html#operational-security) - Documentation on what we just did.