Running a Persistent Pi Session over SSH on macOS
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:
- Open System Settings -> General -> Sharing.
- Enable Remote Login.
- Open its information panel.
- Choose Only these users and add only the account that will run Pi.
- Leave Allow full disk access for remote users disabled unless Pi needs protected macOS directories.
Find the local account name:
Find the Wi-Fi address:
Test SSH from another machine on the same network:
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:
It will normally be in the 100.x.y.z range. Connect from the remote device:
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:
Accept the default location and protect the key with a passphrase.
If ssh-copy-id is available:
Otherwise, display the public key:
Copy its single output line. Log into the MacBook with the account password, then prepare the authorized-key file:
Paste the public key on its own line and save. Then protect the file:
Open a new terminal and verify key authentication before changing any further SSH settings:
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:
Keep Pi alive with tmux
Install tmux on the MacBook:
Create a session or attach to the existing one:
Inside tmux, start Pi:
To detach without stopping Pi, press Ctrl-b, release the keys, and then press d.
Reconnect later:
The shorter version connects and attaches in one command:
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:
If Ollama is launched manually, give it a separate tmux session:
Inspect that session with:
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:
Check all persistent 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:
Detach with Ctrl-b, then d. From another device, reconnect with:
When finished, detach again rather than exiting Pi. The coding session and loaded model remain available for the next connection.