DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
FREEDOM251

Freedom251 › Blog › Home Server

How to secure a Raspberry Pi exposed to the internet

By Freedom251 Team · · 12 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Raspberry Pi reachable from the public internet should be treated as an internet-facing server, even if it sits in a home network. The dependable baseline is to keep Raspberry Pi OS and its packages current, use key-based SSH for a specifically permitted account, expose only services that are actually needed, and enable a firewall without cutting off your own administration session. If public reachability is not essential, use a VPN or a managed remote-access method instead of forwarding SSH or VNC directly. Raspberry Pi’s operational-security guidance and UFW instructions provide the official configuration principles.

  • Inventory the services, users and ports that must remain reachable.
  • Update packages and decide whether the installed Raspberry Pi OS major release is still supported with the latest fixes.
  • Set up and test an SSH key before tightening SSH or enabling a firewall.
  • Restrict SSH logins to named accounts and permit only required inbound services.
  • Use Fail2Ban only as an additional layer, not as a replacement for authentication, updates or a small attack surface.
  • Choose direct exposure, a VPN or Raspberry Pi Connect deliberately, based on the access and recovery control you need.

Decide whether the Pi needs to be public at all

The safest externally reachable service is the one you do not publish. First write down what you need to do from outside the local network: administer the operating system, reach a web application, view a desktop, or provide a service to other people. Each requirement can imply a different access design. Do not expose SSH or VNC merely because port forwarding is available.

As an Amazon Associate I earn from qualifying purchases.

Raspberry Pi documents three broad patterns: direct exposure of services such as SSH or VNC, access through a VPN, and access through an external remote-access service. Its documentation says Raspberry Pi Connect avoids manual network configuration. These are different exposure models, not security guarantees; the official material does not claim that one is universally safest. Compare them against your ability to control users, maintain the network and recover from a bad change at Raspberry Pi’s remote-access documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Access pattern What reaches the Pi Network work you manage When it fits
Direct public SSH or VNC The selected service is reachable from the internet and must withstand unsolicited connection attempts. Port forwarding, firewall rules, account controls, updates and recovery all remain your responsibility. Useful when you need a conventional protocol and can operate the exposed service carefully.
VPN Remote clients first join a private network, then reach the Pi through that path; the Pi’s administration service need not be advertised publicly. You operate the VPN endpoint, client access and routing, in addition to Pi authentication and updates. Appropriate when several private services or controlled administrative access are required.
Raspberry Pi Connect or another external service The service brokers remote access rather than requiring you to publish each local service directly. The service account, client enrollment and local Pi security still need management; Raspberry Pi states that Connect avoids manual network configuration. Useful when you want less router and port-forwarding work and accept the service’s operating model.

Whichever pattern you select, keep the Pi maintained and restrict local accounts. A different route to the screen or shell does not remove the need for secure authentication.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Prepare a recovery path before changing anything

Remote hardening can lock out a perfectly healthy Pi. Before editing SSH or firewall settings, make sure you can reach the machine through a local keyboard and display, a serial or out-of-band console, or another administrator who can do so. Keep a second terminal session logged in while testing changes made from SSH.

  1. Record the Pi’s hostname, local address, internet-facing address or hostname, and the service you currently use to administer it.
  2. List the accounts that genuinely need remote access. Remove or disable accounts that are no longer used through your normal account-management process.
  3. List listening services and the ports that must remain reachable. A local check such as sudo ss -tulpn helps you see what is listening; treat the result as an inventory to verify, not as permission to expose every port.
  4. Keep a copy of the current SSH configuration and firewall state. If a change fails, the local console gives you a way to restore the previous file or rule.
  5. When you change a remote rule, make one change at a time and verify it from a separate connection before closing the known-good session.

Keep Raspberry Pi OS and packages current

Raspberry Pi distinguishes routine package updates within an installed release from moving to a newer major Raspberry Pi OS release. Its configuration documentation says only the most recent major release contains all the latest security fixes, so an old major release should not be treated as equivalent merely because its packages still update. Check the current release policy and upgrade guidance in the Raspberry Pi configuration documentation.

For normal package maintenance, use APT, the package-management method described in Raspberry Pi’s documentation:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt update
sudo apt full-upgrade

Review the proposed changes rather than blindly accepting a remote upgrade. If the kernel, firmware or other core components are updated, schedule a reboot when you can verify that SSH and the services you need return normally. A typical controlled sequence is:

  1. Run sudo apt update and inspect repository or signature errors.
  2. Run sudo apt full-upgrade and read package removals, configuration prompts and service restarts.
  3. Reboot during a maintenance window if the upgrade requires it, then reconnect and check the application.
  4. Investigate a failed update instead of leaving the machine half-upgraded. Do not expose a Pi indefinitely while assuming that an old major release has the same security coverage as the newest one.

Raspberry Pi’s SSH and update guidance is at Raspberry Pi OS: SSH and software updates. Updates are a continuing operating task, not a one-time setup step.

Harden SSH without losing access

Set up a key and test it first

Raspberry Pi explicitly recommends key-based authentication to make SSH more secure. Generate a key on the computer you will use to administer the Pi, and protect the private-key file with a passphrase:

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
ssh-keygen -t ed25519

Copy the public key to the intended account. For a Linux or macOS client with ssh-copy-id, an example is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ssh-copy-id [email protected]

Replace the example address with the Pi’s real address and use the account you selected during your inventory. Then open a second terminal and verify that key authentication works before changing any server policy:

ssh [email protected]

Do not close the original session until the new session has completed a login, run a harmless command and survived a reconnect. If the key is rejected, fix file ownership, permissions, the client’s selected key and the server log while password access is still available.

Allow only the accounts that need SSH

Raspberry Pi documents restricting SSH logins with the SSH server’s AllowUsers or DenyUsers settings. Edit the active SSH server configuration, commonly /etc/ssh/sshd_config, and add a rule that names the account you tested:

AllowUsers piadmin

If more than one account is required, list each approved account on the same directive. Do not combine an accidental deny rule with an allow rule unless you understand the resulting match. Before applying a change, validate the syntax:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo sshd -t

If the check succeeds, restart the SSH service and test a new connection:

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
sudo systemctl restart ssh

Raspberry Pi’s operational-security documentation covers the account-restriction approach. Keep a local recovery account or console route; restricting the wrong username can otherwise strand you.

Consider disabling password authentication only after key login works

Key-based login is the documented recommendation. If every required client supports it and you have tested a second session, you can consider disabling password authentication in the SSH configuration. Make this an intentional change, not a first troubleshooting step:

PasswordAuthentication no

Validate with sudo sshd -t, restart SSH, and test again. Keep your private key protected and maintain a recovery route. If a user, automation job or emergency client still depends on passwords, disabling them before migrating that client will create an avoidable outage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not confuse a port change with SSH security

Moving SSH to a different port can reduce noise in some logs, but it does not replace keys, account restrictions, updates or a firewall. If you do change the listening port, update the firewall rule and every client together, and keep the new value documented. The security control is the authenticated, restricted service—not the number printed on the port.

Configure UFW around the services you actually need

Raspberry Pi recommends UFW for most users. The important sequence is to permit your administration path first, set a restrictive incoming default, enable the firewall, and inspect the active rules. If you are connected over SSH and enable UFW before allowing SSH, you can lock yourself out; Raspberry Pi’s UFW guide calls out this ordering.

  1. Install UFW if it is not already installed:
    sudo apt update
    sudo apt install ufw
  2. Inspect its current state before changing it:
    sudo ufw status verbose
  3. Set the incoming policy to deny and the outgoing policy to allow unless your design requires a different outbound policy:
    sudo ufw default deny incoming
    sudo ufw default allow outgoing
  4. Allow the SSH service you are actively using. For the standard OpenSSH profile:
    sudo ufw allow OpenSSH

    If you deliberately configured another TCP port, allow that exact port instead, for example sudo ufw allow 2222/tcp. Use the real configured port, not both ports by habit.

  5. Add only application ports that the Pi must serve. A web application commonly needs HTTP and/or HTTPS, but permit them only when that application is intended to be reachable:
    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
  6. Enable UFW only after the required remote rule is present:
    sudo ufw enable

    Confirm the prompt, then keep the existing SSH session open while testing.

  7. Inspect the numbered active rules and record them:
    sudo ufw status numbered

Delete rules you no longer need with the rule number shown by status numbered, checking the list again afterward. A default-deny incoming policy is not a substitute for application authentication: it limits which network paths reach the Pi, while the application must still be configured securely.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Expose application services deliberately

For every service, answer three questions: does it need to be reachable from outside, which protocol and port does it use, and which users or clients should be accepted? Permit the smallest set of TCP or UDP ports that answers those questions. If the Pi serves HTTP or HTTPS, allow the required ports and no unrelated management interfaces.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Changing a port number alone does not secure a vulnerable service. Keep the application and its dependencies updated, use their own authentication and encryption settings, and avoid publishing development dashboards, databases or administrative panels that do not need public access. If a service only needs to be used by your own devices, put it behind a VPN or another private access path rather than adding another public exception.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use Fail2Ban as a supplementary control

Fail2Ban watches logs for repeated suspicious attempts and can temporarily block the source. It can reduce the impact of persistent login probing, but Raspberry Pi describes it as an additional layer. It does not replace key authentication, account restrictions, package updates or a firewall that exposes only necessary services.

If you deploy it, confirm that the jail matches the actual service and log format, and monitor for false positives that could block your own address. Keep an out-of-band recovery path because an automated ban can affect an administrator just as it affects an attacker. A correctly configured SSH key and a small exposed service set remain the primary controls.

Compare direct access, a VPN and Raspberry Pi Connect

The right choice depends on what must be reachable and how much network administration you want to operate. Raspberry Pi’s remote-access documentation describes these approaches but does not provide a controlled security comparison or declare one universally safest.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision factor Direct public SSH/VNC VPN first Raspberry Pi Connect or an external service
Exposure The selected protocol is advertised to the public internet and receives unsolicited traffic. Remote users authenticate to the VPN, then use private routes to reach the Pi. The external service brokers access; local service publication may not be required.
Network setup Requires router forwarding, firewall exceptions and careful service configuration. Requires a VPN endpoint, client enrollment, routing and firewall policy. Raspberry Pi says Connect avoids manual network configuration; you still manage the service account and enrolled clients.
Administrative control Fine-grained SSH/VNC accounts and firewall rules are directly under your control, but mistakes are immediately internet-facing. You control who joins the private network and which Pi services are reachable through it. You control local accounts and the Pi while also depending on the external service’s account and availability model.
Recovery concern A bad port-forward, SSH rule or firewall change can remove the only remote path. A VPN or route failure can hide every private service at once. Loss of the service account, enrollment or connectivity can interrupt access; local console recovery remains valuable.

Choose direct exposure when you have a specific protocol requirement and can maintain it. Choose a VPN when several private services or a controlled group of users need access. Consider Connect when avoiding manual network configuration is more important than operating your own VPN. In every case, keep the Pi’s OS, accounts, SSH policy and firewall maintained.

Verify the result from inside and outside

Hardening is complete only when the intended path works and unintended paths fail. Use a second connection or a device on a different network; testing from the same LAN can hide router or public-address behavior.

  • Confirm that the approved SSH account can log in with its key and that an unapproved account cannot.
  • Check sudo ufw status numbered and compare each rule with the written service inventory.
  • From an external network, test only the service you intentionally published. Confirm that administrative ports and unused application ports are not reachable.
  • Verify that the application itself requires its intended authentication and that HTTPS or another configured encryption method works where applicable.
  • Review SSH and application logs for failed logins, unexpected users and repeated probing. Treat a burst of attempts as a reason to verify controls, not as evidence that Fail2Ban alone has solved the problem.
  • After updates or a reboot, repeat the login and application checks. A firewall rule that worked before a service or network change may no longer describe the actual listener.

Troubleshoot common lockouts and failures

SSH stopped working immediately after enabling UFW

If you enabled UFW before allowing SSH, use the local console or another recovery path and add the correct rule. For the standard profile:

sudo ufw allow OpenSSH
sudo ufw status numbered

If SSH uses a custom port, allow that configured TCP port instead. Then verify that the SSH service is running and listening on the same port before trying the external connection again.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The key is rejected but the old password session still works

Keep the working session open. Check that the client is offering the intended private key, that the public key is in the target account’s authorized-keys file, and that the account is not excluded by AllowUsers or DenyUsers. Review the SSH log for the exact rejection, correct the account or key, and test a second connection before changing password policy.

SSH configuration changes prevent all logins

Use the local console to restore the last known-good configuration. Run sudo sshd -t before restarting SSH in future, and keep one known-good session open while testing. If the account restriction names the wrong user, correct it rather than adding broad temporary access that you forget to remove.

The web application works locally but not from outside

Check the application’s listening address and port, the router or VPN path, and the UFW rule. Permit only the required HTTP or HTTPS port, then test from another network. A successful local response does not prove that public forwarding is correct, and an open port does not prove that the application is securely configured.

Repeated login attempts continue after hardening

Internet-facing services will still receive scanning and login attempts. Confirm that key authentication, account restrictions, updates and UFW rules are active. Add Fail2Ban if repeated attempts are relevant to your deployment, but continue to treat it as log-monitoring and blocking assistance rather than the primary defense.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Maintain the baseline over time

Schedule regular APT maintenance, review whether the Pi remains on the newest major Raspberry Pi OS release, and remove firewall exceptions when an application is retired. Recheck SSH users whenever administrators change. Revisit the exposure decision when your needs change: a service that once required public access may later fit behind a VPN or Raspberry Pi Connect. Keep recovery access tested, because a secure configuration that nobody can repair remotely is still an operational risk.

The practical verdict is straightforward: minimize public reachability, update the operating system, authenticate SSH with keys for named users, allow only required services through UFW, and test every change with a recovery path. These controls reinforce one another; none makes the others optional.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Home Serverinternet securityRaspberry PiRemote AccessSSHUFW

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.