Running a Persistent Pi Session over SSH on macOS

Jul 11, 2026

Once Pi and Ollama were running locally on my MacBook, I wanted to use them from another laptop without losing the session whenever the SSH connection dropped. This is the resulting setup:

Remote device -> Tailscale -> macOS SSH -> tmux -> Pi -> Ollama

Tailscale provides private network access without exposing port 22 to the public internet. The standard macOS SSH server handles login, while tmux keeps Pi alive across disconnects.

Enable Remote Login

On the MacBook:

  1. Open System Settings -> General -> Sharing.
  2. Enable Remote Login.
  3. Open its information panel.
  4. Choose Only these users and add only the account that will run Pi.
  5. Leave Allow full disk access for remote users disabled unless Pi needs protected macOS directories.

Find the local account name:

whoami

Find the Wi-Fi address:

ipconfig getifaddr en0

Test SSH from another machine on the same network:

ssh YOUR_USERNAME@192.168.x.x

I do not forward port 22 through the router. Public SSH exposure adds risk and is unnecessary here.

Add Tailscale

Install Tailscale on the MacBook and every remote device, then sign into the same Tailscale account on each one.

Find the MacBook's Tailscale address:

tailscale ip -4

It will normally be in the 100.x.y.z range. Connect from the remote device:

ssh YOUR_USERNAME@100.x.y.z

With Tailscale MagicDNS enabled, the MacBook's hostname can replace the numeric address.

This uses Apple's standard SSH server through the encrypted tailnet. It does not require Tailscale SSH.

Use SSH-key authentication

Generate a key on the remote device:

ssh-keygen -t ed25519

Accept the default location and protect the key with a passphrase.

If ssh-copy-id is available:

ssh-copy-id YOUR_USERNAME@100.x.y.z

Otherwise, display the public key:

cat ~/.ssh/id_ed25519.pub

Copy its single output line. Log into the MacBook with the account password, then prepare the authorized-key file:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys

Paste the public key on its own line and save. Then protect the file:

chmod 600 ~/.ssh/authorized_keys

Open a new terminal and verify key authentication before changing any further SSH settings:

ssh YOUR_USERNAME@100.x.y.z

Add a client alias

On the remote device, add this entry to ~/.ssh/config:

Host pi-mac
    HostName 100.x.y.z
    User YOUR_USERNAME
    IdentityFile ~/.ssh/id_ed25519
    ServerAliveInterval 30
    ServerAliveCountMax 3

Protect the configuration and test the alias:

chmod 600 ~/.ssh/config
ssh pi-mac

Keep Pi alive with tmux

Install tmux on the MacBook:

brew install tmux

Create a session or attach to the existing one:

tmux new-session -A -s pi

Inside tmux, start Pi:

cd ~/path/to/project
pi

To detach without stopping Pi, press Ctrl-b, release the keys, and then press d.

Reconnect later:

ssh pi-mac
tmux attach-session -t pi

The shorter version connects and attaches in one command:

ssh -t pi-mac 'tmux new-session -A -s pi'

Keep Ollama available

The easiest approach is to run the Ollama macOS application and enable launch at login. After connecting through SSH, verify its API:

curl http://127.0.0.1:11434/api/tags

If Ollama is launched manually, give it a separate tmux session:

tmux new-session -d -s ollama 'ollama serve'

Inspect that session with:

tmux attach-session -t ollama

Pi can continue using http://localhost:11434/v1 because it runs on the same MacBook as Ollama.

Keep the Mac awake

I keep the MacBook connected to power with its lid open. A detached tmux session can run caffeinate:

tmux new-session -d -s keepawake 'caffeinate -dimsu'

Check all persistent sessions:

tmux list-sessions

I also enable System Settings -> Battery -> Options -> Wake for network access.

Closing a MacBook's lid normally puts it to sleep. Reliable closed-lid operation requires supported clamshell mode with power, an external display, and input devices. Otherwise, leave the lid open.

There is another startup limitation: after a reboot, FileVault may require a local login before Tailscale, Ollama, and user services become available.

Daily workflow

Start the session on the MacBook:

tmux new-session -A -s pi
cd ~/path/to/project
pi

Detach with Ctrl-b, then d. From another device, reconnect with:

ssh -t pi-mac 'tmux new-session -A -s pi'

When finished, detach again rather than exiting Pi. The coding session and loaded model remain available for the next connection.

References

RSS
https://blog.ssuyi.tw/posts/feed.xml