Stop Port-Forwarding Your Agent Box: Reach a Home Pi Safely With Tailscale SSH

Your agent box sits on a shelf at home. It runs fine for weeks. Then one morning a job fails while you’re at work, and the fix is a two-minute command you can’t run, because the box is behind your home router and you’re not.

The first idea most people have is to forward a port. Open 22 on the router, point it at the Pi, and SSH in from anywhere. It works in five minutes. It’s also the riskiest thing you can do to a box that holds your API keys, your email tokens, and whatever else your agent touches.

There’s a better default for a home agent box: a private network overlay like Tailscale, with SSH running only inside it. Nothing on the box is reachable from the public internet, you can still get in from your laptop or phone, and you decide exactly which devices are allowed to log in.

We run MarketMai’s own agent jobs this way. The Pi that used to run our daily blog job has no open ports on the home router. The only way in is Tailscale SSH from a short list of devices. That setup has saved us from a lot of exposure, and it has also taught us where it slows you down, which we’ll cover too.

Why an open port is a bad trade

A forwarded SSH port gets found fast. Automated scanners sweep the whole IPv4 address space constantly, and a new open port 22 often starts seeing login attempts within hours. If you use password login, you’re betting your agent’s keys on that password. If you use keys only, you’re still running a service the whole internet can talk to, and you’re one bad SSH config change or unpatched bug away from trouble.

An agent box makes this worse than a normal home server, because of what’s on it:

  • API keys for paid models, often with no hard spending cap
  • OAuth tokens for email, calendar, and drive accounts
  • Webhook secrets and bot tokens for chat apps
  • Scripts that can send messages or publish content as you

Anyone who gets a shell on that box doesn’t just get a Pi. They get everything the agent can do.

What Tailscale actually changes

Tailscale builds an encrypted private network between your own devices, using WireGuard underneath. Each device gets a stable private address and a name. Your laptop can reach the Pi by name from a coffee shop, and nothing outside your network can reach it at all.

Two features matter most for an agent box:

  • Tailscale SSH. Instead of managing SSH keys on the Pi, you let Tailscale handle SSH authentication based on who you are on the network. You turn it on with sudo tailscale up --ssh on the Pi.
  • Access control lists. A policy file in the Tailscale admin console decides which users and devices can reach which machines, and which ones can SSH in as which local user.

The router stays closed. No port forwarding, no dynamic DNS, no fail2ban arms race.

Step 1: Close the door you already opened

If you forwarded a port at some point, start there.

  1. Log into your router and delete any port-forwarding rule that points at the agent box. Check for SSH (22), but also for any dashboard or web UI port you opened for convenience.
  2. Check whether UPnP is on. Some apps open ports on their own through UPnP. If you don’t need it, turn it off.
  3. From a phone on cellular data, not your home Wi-Fi, try to reach your public IP on the old port. It should time out.

Do this first, even before Tailscale works. A box you can’t reach for a day is a much smaller problem than a box anyone can reach.

Step 2: Install Tailscale and turn on SSH

On the Pi:

curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up --ssh

The second command prints a login link. Open it, sign in, and the Pi joins your network. Install Tailscale on your laptop and phone too and sign in with the same account.

Then test from your laptop:

tailscale status
ssh pi@your-pi-name

tailscale status should list the Pi as online. If the SSH login works, you now have remote access with nothing exposed.

Two settings to check in the admin console right away:

  • Key expiry. By default, device keys expire after a set period and the device has to log in again. That’s sensible for laptops and annoying for a headless box that nobody logs into. For the agent box, consider disabling key expiry so it doesn’t silently fall off your network some morning. If you leave it on, put the expiry date on your calendar.
  • Device name. Give the box a clear name like agent-pi, not raspberrypi. You’ll type it a lot, and so will your scripts.

Step 3: Write an ACL that says who can get in

Out of the box, many Tailscale setups allow every device on your network to reach every other device. For an agent box, narrow it.

A minimal policy has three ideas:

  • Tag the agent box, for example tag:agent, so rules target the role, not a device name.
  • Allow only your own user to reach tag:agent over SSH.
  • Allow SSH only as the specific local user the agent runs as, not as root.

In the SSH section of the policy, there’s a choice between accept and check. With accept, a device you’ve already signed in on can SSH straight in. With check, Tailscale asks you to re-authenticate in a browser before the session opens, and remembers that for a period you set.

check is the safer setting, and it’s what we use. If someone steals your laptop while it’s unlocked, they still hit a sign-in wall before they reach the agent.

Step 4: Plan for the approval step

Here’s the part nobody tells you about. The check mode that protects you also gets in the way when you’re in a hurry, and it gets in the way of automation even more.

On our own pipeline, a few morning fixes stalled for exactly this reason. Something needed a command run on the Pi. The SSH session hit the check step and printed a sign-in link. Nobody could finish the fix until the owner opened that link on his phone and approved it.

You don’t have to choose between safe and usable. Plan for it:

  • Set a sensible check period. If you re-authenticate once in the morning, a check period of several hours covers the rest of your working session without re-prompting.
  • Keep the approval device in your pocket. The sign-in link opens in a browser. Make sure the account you approve with is signed in on your phone, so approval takes ten seconds instead of a password reset.
  • Don’t route routine work through interactive SSH. If your agent needs to deploy, publish, or run a nightly job, that job should live on the box itself or in CI, not in an SSH session someone has to approve. Save SSH for fixing things.
  • Give automation its own path. If a remote system truly has to reach the box, give it a separate tagged identity with access to exactly one port or one command, instead of reusing your personal SSH access.

The rule of thumb: interactive SSH is for humans, and it’s fine for it to ask a human. Scheduled work shouldn’t depend on it.

Step 5: Run the same health check from outside

Once remote access is private, add one check you can run from anywhere:

ssh pi@agent-pi 'uptime; df -h /; systemctl --failed --no-pager; tail -n 20 ~/agent/logs/latest.log'

That one line tells you whether the box is up, whether the disk is filling, whether any service failed, and what the agent did last. Save it as an alias on your laptop. When something looks wrong, you get the full picture in one command instead of poking around.

If tailscale status shows the Pi offline, you know the problem is the box or your home internet, not your agent. That distinction alone saves a lot of debugging.

Step 6: Review access once a quarter

Private networks pick up clutter. Old laptops, a phone you replaced, a test VM you forgot. Every one of them is a device that might be allowed to reach your agent.

Once a quarter:

  1. Open the machines list in the admin console and remove anything you don’t recognize or no longer use.
  2. Re-read your ACL and confirm only the devices and users you expect can reach tag:agent.
  3. Check key expiry dates on anything that still has them.
  4. Confirm the router still has no forwarded ports, since firmware updates sometimes reset settings.

It takes ten minutes and keeps the “only my devices can reach this” promise true.

What this doesn’t fix

Tailscale closes the network door. It doesn’t make the box itself safe. You still want the agent running as its own Linux user, secrets out of plain-text URLs, security updates applied, and a backup you’ve actually restored. Private access just means a mistake in those areas is much harder for a stranger to reach.

The short version

Don’t forward a port to your agent box. Close any you already opened, put the box on Tailscale with SSH enabled, tag it, and write an ACL that lets only you in as a non-root user with re-authentication turned on. Then plan around that approval step: keep scheduled work off interactive SSH, keep your approval device handy, and set a check period that matches how you work.

Let your agent audit its own exposure

You can hand the quarterly review to your agent once you’ve done it by hand. Start with MarketMai’s free AI prompt pack and adapt one into a “list every listening port on this box, every device allowed to reach it, and every credential stored on it, then flag anything reachable from outside the private network” task, and review its list before you change anything. For hardening checklists, monitoring checks, and cron configs built for self-hosted agents, the OpenClaw Agent Ops Toolkit has the full set, and the MarketMai Ultimate Bundle puts 13 prompt, automation, and agent-operations products in one $49 download.

More from the build log

Suggested

Want the full MarketMai stack?

Get the core MarketMai guides and operator playbooks in one premium bundle for $49.

View Bundle