Guide · Deploy
Send credentials to your Linux server
A service on your own Linux server needs API keys and app passwords. Pasting them into files over ssh leaves no record of what's there, and the copy on your Mac and the one on the server drift apart.
In shortGive the server a script that stores one credential from standard input, let your account run it with sudo and no password, name each Latchkey item ADAPTER.ACCOUNT, and link the environment with lk remote link ENV ssh host=… script=…. Every lk push asks you with Touch ID, then sends each value over ssh on standard input.
How it works
The values stay in your Mac's keychain, where you can see, rotate and audit them. The server keeps its own copy, one root-only file per credential, which the service loads at start, for example with systemd's LoadCredential=. Latchkey's job is the delivery: it runs your server's script once per item, over your own ssh connection and keys, with the value on standard input, so it never appears in a command line, an environment variable or your shell history.
The service never talks to Latchkey, and keeps running with its last values while your Mac is off.
Set it up
-
Give the server a credential script
Latchkey runs it as
sudo -n bash SCRIPT ADAPTER ACCOUNT --stdinand sends the value followed by one newline. The script must read at most 64 KiB, strip that one newline, store the value, and printstored ADAPTER.ACCOUNTwhen it has; anything else counts as a failure. A minimal one, withmyappas the example service:/srv/myapp/add-credential.sh #!/bin/bash set -euo pipefail [[ $# -eq 3 && $3 == --stdin && ! -t 0 ]] || { echo "usage: add-credential.sh ADAPTER ACCOUNT --stdin" >&2; exit 64; } name="$1.$2" [[ $name =~ ^[A-Za-z0-9][A-Za-z0-9_-]*\.[A-Za-z0-9][A-Za-z0-9._-]*$ ]] || { echo "bad name" >&2; exit 64; } value=$(head -c 65536; printf x); value=${value%x}; value=${value%$'\n'} [[ -n $value ]] || { echo "empty value" >&2; exit 1; } dir=/etc/myapp/credentials umask 077 tmp=$(mktemp "$dir/.$name.XXXXXX") printf %s "$value" > "$tmp" && mv "$tmp" "$dir/$name" systemctl restart myapp echo "stored $name"Point the service at those files, for example with a
LoadCredential=NAME:/etc/myapp/credentials/NAMEline for each credential in its unit, so it reads them from$CREDENTIALS_DIRECTORY. -
Let your account run it without a password
A push has no terminal, so
sudocan't ask for one. Allow exactly that script, and check from your Mac:/etc/sudoers.d/myapp-credentials you ALL=(root) NOPASSWD: /usr/bin/bash /srv/myapp/add-credential.sh *Your Mac ssh myserver sudo -n -l bash /srv/myapp/add-credential.shIt prints the command when the rule is in place.
myserveris the host as named in your SSH config. -
Store each credential under its name
Name items
ADAPTER.ACCOUNT: Latchkey splits at the first dot. Both parts start with a letter or digit and use letters, digits,_and-; the account may also contain dots.Terminal lk set myapp/production/bluesky.someone.bsky.social --kind tokenYou're asked for the value without it being shown, and saving asks for Touch ID.
-
Link the environment to the server
Terminal lk remote link myapp/production ssh host=myserver script=/srv/myapp/add-credential.shLinking asks once. The host and script may hold only characters a shell reads literally, and a link synced from another Mac is checked again before each push.
-
Push, and approve with Touch ID
Terminal lk push myapp/production --only myapp/production/bluesky.someone.bsky.socialThe approval panel names the server, the script and every item. A server counts as production, because its script restarts the service, so tick I mean to change production, then touch the sensor. Each credential the server confirms prints as
pushed.
Keep it current
Change a value in Latchkey and push again; the script replaces the file and restarts the service. lk remote status myapp/production lists items never pushed to the server and items changed since they were. The server can't list what it holds, so that comes from Latchkey's own record of what it pushed, not from the server.
What this doesn't do
- It doesn't remove credentials from the server. Unlinking stops future pushes; deleting a file on the server is yours to do.
- The server keeps plain-text copies, readable by root. Protect the server as you would any place that holds them.
- Each push waits for your approval on your Mac, so a script or agent can start one but can't finish it without you. Agents have no push tool.
- It's in the direct download only: the Mac App Store version can't run ssh. One value is at most 64 KiB, and empty values aren't sent.
The script contract has every rule in one place, and Push env vars to your deploy platforms covers Vercel, GitHub, Railway and Fly.