0
0
Raspberry Piprogramming~10 mins

Securing Raspberry Pi (SSH keys, firewall) - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Securing Raspberry Pi (SSH keys, firewall)
Generate SSH Key Pair
Copy Public Key to Pi
Disable Password Login
Configure Firewall Rules
Test SSH Connection
Secure Pi Access Established
This flow shows the steps to secure Raspberry Pi by setting up SSH keys and firewall rules to allow safe remote access.
Execution Sample
Raspberry Pi
ssh-keygen -t ed25519
ssh-copy-id pi@raspberrypi
sudo ufw allow ssh
sudo ufw enable
This code generates SSH keys, copies the public key to the Pi, allows SSH through the firewall, and enables the firewall.
Execution Table
StepActionCommand/SettingResultNext Step
1Generate SSH key pair on local machinessh-keygen -t ed25519Created private and public keysCopy public key to Pi
2Copy public key to Raspberry Pissh-copy-id pi@raspberrypiPublic key added to Pi's authorized_keysDisable password login
3Disable password login on PiEdit /etc/ssh/sshd_config to set PasswordAuthentication noPassword login disabled, only keys allowedConfigure firewall
4Allow SSH through firewallsudo ufw allow sshFirewall rule added to allow SSH port 22Enable firewall
5Enable firewallsudo ufw enableFirewall activated with SSH allowedTest SSH connection
6Test SSH connectionssh pi@raspberrypiConnected without password promptSecure Pi access established
7End-SSH key authentication and firewall activeProcess complete
💡 SSH key authentication works and firewall blocks unwanted access, securing the Raspberry Pi.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
SSH KeysNoneKeys generatedPublic key copied to PiPassword login disabledFirewall allows SSHFirewall enabledSSH key auth active
Firewall StatusDisabledDisabledDisabledDisabledRule addedEnabledActive with SSH allowed
SSH AccessPassword loginPassword loginKey login enabledPassword login disabledKey login enabledKey login enabledKey login only
Key Moments - 3 Insights
Why do we disable password login after copying the SSH key?
Disabling password login (Step 3) ensures only devices with the private SSH key can connect, improving security as shown in execution_table row 3.
What happens if the firewall does not allow SSH port 22?
If the firewall blocks SSH (before Step 4), remote connections fail even with correct keys. Execution_table row 4 shows adding the rule to allow SSH.
Why test SSH connection at the end?
Testing (Step 6) confirms the setup works: SSH connects without password prompt and firewall allows it, as shown in execution_table row 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result after Step 2?
APublic key added to Pi's authorized_keys
BFirewall enabled
CPassword login disabled
DSSH connection tested
💡 Hint
Check the 'Result' column for Step 2 in the execution_table.
At which step is the firewall activated?
AStep 4
BStep 3
CStep 5
DStep 6
💡 Hint
Look for 'Firewall activated' in the 'Result' column of execution_table.
If password login is not disabled, what changes in the variable_tracker for SSH Access?
ASSH Access changes to 'Key login only' after Step 3
BSSH Access remains 'Password login' after Step 3
CFirewall Status changes to 'Enabled' earlier
DSSH Keys are not generated
💡 Hint
Check the 'SSH Access' row in variable_tracker after Step 3.
Concept Snapshot
Securing Raspberry Pi:
1. Generate SSH key pair locally (ssh-keygen).
2. Copy public key to Pi (ssh-copy-id).
3. Disable password login in sshd_config.
4. Allow SSH port in firewall (ufw allow ssh).
5. Enable firewall (ufw enable).
6. Test SSH connection uses keys only.
Full Transcript
This visual execution shows how to secure a Raspberry Pi by using SSH keys and firewall rules. First, you generate an SSH key pair on your local machine. Then, you copy the public key to the Pi to allow key-based login. Next, you disable password login on the Pi to prevent password attacks. After that, you configure the firewall to allow SSH connections and enable it. Finally, you test the SSH connection to confirm it works without a password prompt. The variable tracker shows how SSH keys, firewall status, and SSH access method change step-by-step. Key moments clarify why disabling password login and firewall rules are important. The quiz tests understanding of each step's result and effects on security.