git-sshkey is an ultra-fast, cross-platform Rust CLI that binds a specific SSH identity from your active ssh-agent to a single Git repository or commands.
It solves three common problems:
- SSH identity exhaustion: When your agent has multiple keys loaded, servers often reject connections after too many failed attempts.
- Preserving global SSH binary/path behavior: Applies local repository overrides while respecting your globally configured SSH binary.
- Fast, offline default fallback and cache fast-path: Keeps developer experience lightning-fast without redundant network checks or prompt fatigue.
- Native Git Subcommand Workflow: Responds directly to
git sshkey ... - Smart Probing with Cache Fast-Path (
-a/--auto): Automatically probe SSH keys against the remote. Successful hits are cached locally under~/.ssh/git-sshkey/cache/for zero-delay operations. - Self-Healing Cache: If a cached key fails (e.g. key revoked), the cache is automatically cleared and re-probed.
- Interactive Identity Picker: Seamless dropdown selection powered by
dialoguerreading directly fromssh-add -L. - Global Default Identity (
git sshkey default): Configure a global fallback identity in git config (git-sshkey.default). - Instant Command Generation (
git sshkey command): Outputs the exactcore.sshCommandstring for any key or remote url instantly. If a default is set, it executes offline without prompting or network delays. - Local-Only
core.sshCommandBinding: Isolate SSH keys locally per repo. - Windows Path Compatibility: Auto-normalizes Windows directory backslashes into forward slashes inside Git commands, preventing escaping/parsing bugs.
Install from local source:
cargo install --path .This installs git-sshkey into Cargo's bin directory (usually ~/.cargo/bin), which should be on your PATH.
Once installed, Git will automatically resolve git sshkey subcommands.
git sshkey- Show help and usage instructions.git sshkey info- Show current environment status (inherited binary, global default, local override).git sshkey list- List identities currently loaded inssh-agent.git sshkey pick- Interactively select an identity fromssh-agentand bind it to the local repository.git sshkey default [key]- Get, set, or interactively pick the global default fallback identity. Highlights current default in picker.git sshkey command [key] [--remote <url>]- Output the SSH command string for a specific key, remote, or current default instantly.git sshkey <git-command> ...- Run any Git command temporarily using a selectedssh-agentidentity.git sshkey run <git-command> ...- Execute a Git command whose name conflicts with an internalgit-sshkeysubcommand.git sshkey test- Run a silent auth probe against the default remote URL.git sshkey clear- Remove localcore.sshCommandoverride from the repository.
When running with the --auto flag, git-sshkey tries to authenticate against your remote repository in the following order:
- Cache Lookahead: Fetches the hashed remote URL cache key under
~/.ssh/git-sshkey/cache/. If hit, it tries that key first (0ms network delay). - Global Default: If cache misses or fails, it falls back to your globally configured default key (
git-sshkey.default). - Sequence Probe: If both miss/fail, it probes all remaining loaded keys sequentially using
git ls-remote --exit-code <url> HEAD. - Caching & Healing: Working keys are cached. Revoked or failing keys automatically trigger cache invalidation and a fresh probe cycle.
When binding a key, git-sshkey extracts and materializes public key files dynamically under ~/.ssh/git-sshkey/:
~/.ssh/git-sshkey/{comment}.pub(unique name-based)~/.ssh/git-sshkey/{comment}-{short_hash}.pub(collision fallback)~/.ssh/git-sshkey/key-{short_hash}.pub(when comment is missing or reserved system words)
MIT. See LICENSE.