Load SSH keys from 1Password into your ssh-agent on headless Linux servers.
Private keys are piped directly from 1Password to ssh-add and never touch the filesystem.
- A 1Password account with SSH keys stored in a vault
- A 1Password Service Account with read access to that vault
- The 1Password CLI installed (
op)
There are two ways to install: the install script or manually.
The install script downloads op-ssh-load, prompts you for your service account token, and configures everything:
bash <(curl -sSfL https://raw.githubusercontent.com/narasaka/op-ssh-load/main/install.sh)- Download the script:
mkdir -p ~/.local/bin
curl -sSfL https://raw.githubusercontent.com/narasaka/op-ssh-load/main/op-ssh-load -o ~/.local/bin/op-ssh-load
chmod +x ~/.local/bin/op-ssh-loadMost Linux distributions add ~/.local/bin to your PATH by default. If yours does not, add this to your shell's config file (~/.bashrc, ~/.zshrc, ~/.profile, etc.):
export PATH="$HOME/.local/bin:$PATH"- Configure your service account token:
mkdir -p ~/.config/op
chmod 700 ~/.config/op
echo 'YOUR_SERVICE_ACCOUNT_TOKEN' > ~/.config/op/service-account-token
chmod 600 ~/.config/op/service-account-tokenReplace YOUR_SERVICE_ACCOUNT_TOKEN with your actual token (starts with ops_).
Alternatively, export it as an environment variable:
export OP_SERVICE_ACCOUNT_TOKEN="ops_..."The install script (Option A) offers to configure this automatically.
To set it up manually, add this to your shell's config file (~/.bashrc, ~/.zshrc, ~/.profile, etc.). The snippet is POSIX-compatible and works in Bash, Zsh, and other POSIX shells:
SSH_ENV="$HOME/.ssh/agent-env"
if [ -z "${SSH_AUTH_SOCK:-}" ]; then
if [ -f "$SSH_ENV" ]; then
. "$SSH_ENV" > /dev/null
if ! kill -0 "$SSH_AGENT_PID" 2>/dev/null; then
eval "$(ssh-agent -s)" > /dev/null
echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK; export SSH_AGENT_PID=$SSH_AGENT_PID" > "$SSH_ENV"
chmod 600 "$SSH_ENV"
fi
else
mkdir -p "$HOME/.ssh"
eval "$(ssh-agent -s)" > /dev/null
echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK; export SSH_AGENT_PID=$SSH_AGENT_PID" > "$SSH_ENV"
chmod 600 "$SSH_ENV"
fi
fiThen reload your shell (or open a new terminal):
exec "$SHELL"Load all SSH keys from 1Password:
op-ssh-loadList available SSH keys without loading them:
op-ssh-load --listLoad a specific key by name:
op-ssh-load "GitHub"Clear the agent and reload all keys:
op-ssh-load --clearVerify keys are loaded:
ssh-add -l- The script reads your service account token from
~/.config/op/service-account-token(or theOP_SERVICE_ACCOUNT_TOKENenvironment variable). - It queries 1Password for all items with the "SSH Key" category across accessible vaults.
- For each key, it calls
op readwith the?ssh-format=opensshquery parameter to get the private key in OpenSSH format. - The key is piped directly to
ssh-add /dev/stdin. The private key is never written to disk.
- Sign in to 1password.com.
- Go to Integrations, then Service Accounts.
- Create a new service account.
- Grant it read access to the vault(s) containing your SSH keys.
- Copy the token and store it as described above.
MIT