Home/Guides/How to store env vars and API keys for multiple projects on a remote Mac mini

How to store env vars and API keys for multiple projects on a remote Mac mini

Updated · airankrush

What this guide covers

When you finish, each project's secrets are isolated from the others, they do not appear in repositories or command line arguments, and you can revoke them one by one when the rental ends. You need: permission to manage keys in each provider's dashboard.

Steps

  1. Issue keys for this machine only

    Do not copy over the key your own computer is using. In each provider's dashboard, create a new one for this machine, put the purpose and date in its name, give it only as much permission as it needs, and set a spending cap and an expiry wherever those are available. The payoff comes in the last step: when the rental ends or you suspect a leak, you revoke just this one key, and your local and production environments are unaffected.

  2. Generate keys on the remote Mac where you can, and skip the clipboard

    Log in to the provider's dashboard in the browser inside the remote desktop, generate the key, and store it straight in the keychain as described in the next step. The key then never passes through your own computer or the clipboard sync of the remote access software. If you have to bring one over from your computer, clear the local clipboard after pasting. Never send a full key to support, paste it into a ticket or include it in a screenshot.

  3. Store in the keychain, retrieve with a command

    The security command built into macOS can read and write the keychain. To store:

    security add-generic-password -a "$USER" -s myproj-api-key -w

    According to the system manual, putting -w at the end prompts you for the password value, so the secret does not appear in the command or the history. To retrieve: security find-generic-password -a "$USER" -s myproj-api-key -w. In a startup script, write export API_KEY="$(security find-generic-password -a "$USER" -s myproj-api-key -w)", and use a different service name for each project.

  4. Three points about .env files

    Many frameworks read .env by default. You can use it, as long as you do the following: chmod 600 .env so that only you can read and write it; have .env in .gitignore and confirm with git status that it is not tracked; and commit only a .env.example with no real values to the repository. Give each project its own .env. Do not export a pile of global secrets in ~/.zshrc, because then every process and every agent can read the keys of every project.

  5. Do not put secrets in command line arguments

    This needs particular care on a rented machine. The platform runs the necessary operational and security monitoring, and its scope includes running processes. The path and launch arguments of a process are part of that operational information, and the help documentation also warns that arguments may reveal clues about your business. So do not pass a secret in the form --token=xxx; use an environment variable, a config file or standard input instead. The platform does not record the screen or the content of your business data, and it does not proactively access what is on the device, but putting a secret in an argument means placing it in the operational information yourself.

  6. After a restart, the keychain unlocks only when you log in

    The login keychain unlocks when your account logs in to the desktop. After the machine restarts and before you log in, scripts cannot read the secrets in it. User-level auto-start jobs only run after login anyway, so there is usually no conflict. But if you start a service by hand from a command line session without having logged in to the desktop, the read fails. After a restart, log in once through the remote desktop first.

  7. The revocation checklist before the rental ends

    The machine is reclaimed and reinstalled after the rental ends, but revoking is your job, and it has to happen before you hand the machine back: revoke each key and token issued for this machine in the provider dashboards; delete this machine's SSH public key on GitHub; sign out of command line tools, browsers and your Apple account; and confirm that the .env.example and config you want to keep are in your own repository. As you go, keep a note in your password manager of which keys were issued for this machine, and work through that list when the time comes.

FAQ

If I keep keys on a rented machine, can the platform see them?

The platform does not record the screen or the content of your business data, and it does not proactively access what is on the device. But this is not an environment with no monitoring at all: processes, network connections and configuration state fall within operational and security monitoring. See this explanation. For highly sensitive keys, decide whether to put them there according to your own organization's requirements.

What if I suspect a key has leaked?

Revoke it in the provider's dashboard immediately and issue a new one, then check the usage records. Because every machine and every project has its own key, the impact stays contained.

Can I sync passwords over with iCloud Keychain?

You can sign in with your own Apple account. We suggest a dedicated work account, and you should decide for yourself which data to sync. Find My Mac has to stay turned off, and you need to sign out of the account before the rental ends.

How do I give an agent the keys it needs?

Give it only the one key the current project needs, injected through that project's .env or startup script. Do not let an agent read the place where you keep all your keys.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All guides