Guide · SSH
Use your secrets on another Mac over SSH
You work on a second Mac through SSH and its commands need keys that live on your laptop. Copying a .env file across leaves a plain-text copy behind.
In shortConnect with ssh -R to forward Latchkey's socket, set LATCHKEY_SOCKET on the other Mac, and run latchkey run there. The request reaches the app on your own Mac, which asks you to approve each read of an item that needs approval.
Why files are the wrong answer
A remote shell has no Touch ID and no keychain of yours. The usual fixes are to copy the env file over, or to paste values into the session. Both leave the values in a file or in shell history on a machine you may not control as tightly as your laptop.
Latchkey's command-line tool never touches the keychain. It asks the app over a Unix socket. If you forward that socket over SSH, the tool on the far Mac asks the app on your Mac, and the approval appears where you are sitting.
Set it up
Your Mac needs the Latchkey app running; the other Mac needs the latchkey tool, which is macOS only. Forwarding needs the direct-download app on your Mac: the Mac App Store version doesn't support it yet. If the other Mac has the App Store version installed, set LATCHKEY_BROKER=direct there too. $USER expands to your login name on each Mac: use the same name on both, or put a fixed name in both commands.
-
Forward the socket when you connect
Run this on your own Mac, with the Latchkey app running.
devmacis an example host name.Your Mac ssh -o StreamLocalBindUnlink=yes \ -R /tmp/latchkey-$USER.sock:"$HOME/Library/Application Support/Latchkey/broker.sock" \ devmac -
Point the tool at the forwarded socket
In that SSH session, on the other Mac, set
LATCHKEY_SOCKETto the path you forwarded to.The other Mac export LATCHKEY_SOCKET=/tmp/latchkey-$USER.sock -
Run your command
Use
latchkey runas you would at home. Hereshop/developmentis an example environment.The other Mac latchkey run --env shop/development -- npm test -
Approve on your Mac
The approval panel opens on your own Mac. It says the request came over SSH and shows what the tool on the other computer says it is running, marked as unchecked. Approve with Touch ID, or deny. A request nobody answers is denied after two minutes.
What is different from working locally
- Each read asks, unless the item is set to need no approval. Your Mac sees only your
sshclient, not the program on the other computer, so grants don't apply and can't be made over the connection. latchkey statuson the other Mac says it can't check the app's signature through a forwarded socket.- Copying to the clipboard is refused over SSH, because the clipboard would be on the other computer.
The Agents and MCP reference has the same setup in short form, and Security explains how Latchkey identifies callers.
What this doesn't do
- It doesn't sync secrets to the other Mac. Nothing is stored there: the value goes to the command you run. Syncing items to a second Mac through iCloud Keychain is a separate feature, and its second-Mac test is still pending.
- The forwarded socket on the other computer is created owner-only, using sshd's default
StreamLocalBindMask. Anyone with your account there can use it while you are connected. - Your Mac can't verify the far side. The program name in the panel is only what the tool reports. Read the command, and deny what you don't recognise.
- Once a command has a value, Latchkey can't control what that command does with it.