Skip to content

Keychain on Linux and in containers

maruhi stores its token and this device's key in the OS keychain and never falls back to plaintext files. Set up a Secret Service on headless Linux, WSL, dev containers, and Codespaces.

maruhi persists exactly two secrets on a machine: the API token that maruhi login obtains, and this machine’s device key, created by maruhi key generate, maruhi device add or maruhi key recover. Both live in the OS keychain, under the service name maruhi, and nowhere else — when no keychain is available, the commands fail instead of writing a plaintext file.

On macOS this is the system Keychain and on Windows the Credential Manager (experimental), with nothing to set up. On Linux, maruhi uses the freedesktop Secret Service: a D-Bus API provided by GNOME Keyring or KWallet. Desktop distributions ship one out of the box, so this page is about the machines that do not — servers, WSL, dev containers, and GitHub Codespaces.

You have two ways through. maruhi agent needs no packages and no setup: it keeps the token and key in the memory of one shell session and forgets them when the shell exits. A Secret Service takes five lines to set up and persists them across sessions. Pick by how long the machine lives.

How the failure looks

You will see one of two messages. Both mean the same thing — no usable Secret Service in this environment — and both have the same fix (the next section). Which one appears depends on the operation, not on the exact cause, so do not diagnose from the wording:

Cannot access the OS keychain (tokens and keys cannot be stored in this environment). maruhi does not fall back to plaintext files — run maruhi agent -- <shell> to keep them in memory for that shell’s lifetime, or pass a token via the MARUHI_TOKEN environment variable

This is the general failure: the keychain answered with an error right away (a bus exists but nothing provides the Secret Service on it), or a keychain read hung — without a session bus the operation never gets an answer, and maruhi cuts the wait after 30 seconds.

Writing to the OS keychain timed out. […] maruhi does not fall back to plaintext files

This one appears when a keychain write hangs — maruhi login or maruhi key generate storing a value. It carries extra instructions because a timed-out write cannot be cancelled and may still complete in the background.

Keep secrets in memory for one shell: maruhi agent

maruhi agent is the ssh-agent idea applied to maruhi: a process that holds the token and the device key in its own memory, and hands them to the maruhi commands that run inside it over a Unix domain socket. Nothing touches the disk — the only file it creates is the socket itself (in a private 0700 directory under $XDG_RUNTIME_DIR, or the temp directory), and the socket carries nothing while idle.

Start it with the shell you want to work in, written after --, exactly like maruhi run:

maruhi agent -- bash

Inside that shell, every maruhi command uses the agent instead of the OS keychain (they find it through the MARUHI_AGENT_SOCK variable the agent sets). Sign in and get your key the usual way:

maruhi login                        # the token now lives in the agent, not in a keychain
maruhi device add                   # registers this shell as a device of yours (approve from a device you have) …
maruhi key generate                 # … or, on a brand-new account, creates your first device key and the reserve key there
maruhi run -- npm run dev           # works as on any other machine
exit                                # the agent forgets everything and exits with the shell

What to know before relying on it:

  • Lifetime is the shell’s lifetime. When the command you started exits, the agent discards the token and key and removes its socket. There is nothing to clean up and nothing to leak into the next session — and nothing survives, so a new shell means maruhi login (and maruhi device add) again — and the device key the previous shell held is gone, so revoke it (maruhi device revoke <label>) rather than leave it on your projects. For machines you return to daily, set up the keyring below instead.
  • Getting a key in means registering a device. maruhi device add generates a key for this shell and prints its fingerprint; approve it with maruhi device approve <fingerprint> on a device you already have (Devices). The approving end needs a human interactive terminal (AI-agent environments are refused), and the server allows five device-add requests per user per hour. Do not script it. maruhi key recover with the recovery code is for when no device of yours is left (Recover your key) — same terminal rule, five fetches per hour.
  • Optionally forget the key early. maruhi agent --key-ttl 2h -- bash drops the device key from memory two hours after it is stored while keeping the token, so a shell left open on a shared machine does not hold the key indefinitely. The next command that needs the key says it is missing; that device key is gone for good, so register the shell again with maruhi device add and revoke the forgotten key. Accepted units are s, m, and h.
  • Same trust boundary as a keychain. Any process running as your user can talk to the socket (the directory and the socket are 0700 / 0600), just as it could read a Secret Service keyring you unlocked. Commands started by maruhi run do not inherit MARUHI_AGENT_SOCK — like every other MARUHI_* variable, it is not passed to the child — so the tool you run with injected values does not silently get a session of its own.
  • One agent at a time. Starting maruhi agent inside an agent session is refused; the outer one already holds your keys. maruhi logout inside the session removes the token from the agent and revokes it on the server, the same as it would with a keychain. maruhi agent status lists what the session holds (which server’s token, whose key) without showing any value.
  • Linux and macOS. Windows has the Credential Manager and needs none of this; maruhi agent is refused there.

Set up a keyring on a headless machine

Verified on Ubuntu 24.04. Install GNOME Keyring, D-Bus session support, and the Secret Service client library once (the dbus-run-session tool used below ships in dbus-bin, which dbus-user-session pulls in):

sudo apt-get install -y gnome-keyring dbus-user-session libsecret-1-0

Then, in each shell session where you want to use maruhi, start a session bus and unlock the keyring inside it. Type these lines into an interactive terminal — the first one starts a nested shell that the rest run in, so this block is not meant to be saved as a script:

dbus-run-session -- bash            # a session bus for this shell and its children
read -rsp "Keyring password: " pw && echo
printf '%s' "$pw" | gnome-keyring-daemon --unlock --components=secrets
unset pw
maruhi login                        # keychain-backed commands now work in this shell

What this does, and what to expect:

  • The first unlock creates ~/.local/share/keyrings/login.keyring, encrypted with the password you typed. Later unlocks open the same file, so tokens and keys survive reboots and new sessions — only the daemon is per-session, the data is not.
  • The password must not be empty. With empty input the daemon tries to open a graphical prompt instead, which a headless shell cannot show, and the command hangs until maruhi’s 30-second guard reports the timeout.
  • The keyring file is only as strong as that password: anyone who has both the file and the password can read every secret in it. Treat it like the credential it is.
  • dbus-run-session needs no systemd and no desktop session, which is why the same five lines work unchanged over SSH, in WSL2, and inside container shells.

Dev containers and Codespaces

The setup above applies inside containers too: put the three packages in the image (or postCreateCommand), and run the session-bus + unlock lines in each shell — both paths below need a working Secret Service first (maruhi login writes to the keychain). On top of that, a container rebuild discards the home directory, and with it ~/.local/share/keyrings — the new container is, from maruhi’s point of view, a new machine with no token and no device key. A container is a device like any other: one codespace, one device key, added once and revoked when the codespace is deleted. The two bullets decide whether that key survives a rebuild:

  • Persist the keyring directory. Mount a volume (or use your dotfiles mechanism) so ~/.local/share/keyrings survives rebuilds. After the per-shell unlock, your token and device key are right where you left them.
  • Treat every rebuild as a new device. Run maruhi login, then maruhi device add --label <codespace-name>: the container prints a fingerprint, you run maruhi device approve <fingerprint> on your laptop, and the container gets a device key of its own — nothing secret moves, and you keep your place in every project without being re-invited (Devices). Each rebuild leaves the previous key behind on your projects, so revoke it (maruhi device revoke <label>), and the CLI then rotates every environment that key could open. That is why this is not for frequent or automated rebuilds: every rebuild costs an approval on your laptop, a revocation and a rotation, and the server accepts five device-add requests per user per hour. Prefer the volume when rebuilds are frequent. When a short-lived container must have a key, give it a narrow cap at approval (maruhi device approve <fingerprint> --cap member --env dev), so that revoking it rotates dev only and it can never read production.

If you would rather not install a keyring in the container at all, run the same two commands inside maruhi agent -- bash (above): no packages, no unlock step, and the same limits — the device key lives for that shell only, so --key-ttl bounds how long a forgotten shell keeps it, and the key still needs revoking when the shell is gone. The shortest path for a Codespace: maruhi agent -- bash, maruhi login, maruhi device add, approve on your laptop. maruhi key recover (with the recovery code) is not a way to set up a container: it is for when no device of yours is left, and the five fetches per hour are meant for that.

What works without a keychain

  • GitHub Actions needs none of this. maruhi ci run and maruhi ci sync authenticate with the job’s OIDC token and hold key material in memory only — see GitHub Actions.
  • Session-only commands accept MARUHI_TOKEN. Commands that need a session but not your device key (metadata-only reads such as maruhi schema) authenticate with the MARUHI_TOKEN environment variable, bound to one server with MARUHI_TOKEN_ORIGIN. The provisioning procedure — issuing a named token on an interactive workstation with maruhi login --token-name <name> --token-ttl-days <days> --show-token — is described in the self-hosting runbook under “Provisioning unattended runtimes”.
  • Value operations do not. maruhi run, push, and pull decrypt with this device’s key, and the device key lives only in the keychain or in a running maruhi agent. There is no environment-variable substitute for it, by design.
© 2026 maruhi contributors

Type to search…

↑↓ navigate↵ selectEsc close