CLI to manage multiple GitHub SSH accounts on one machine and wire repos to the right identity.
Published on npm as @samyou/sshgit.
npm install -g @samyou/sshgitRequires Node.js 18+.
sshgit init
sshgit account add --provider github --account work --email you@company.comAfter sshgit account add, copy the .pub key to GitHub (before sshgit account test or sshgit repo use):
sshgit account copy-pub github-workThen paste it into GitHub at Settings -> SSH and GPG keys:
https://github.com/settings/keys
Rewire remote origin url (optional)
sshgit repo use github-work
# show all configured account aliases
sshgit account list
# add a GitHub account
sshgit account add --provider github --account personal --email you@example.com --git-name "Your Name"
# test one specific alias
sshgit account test github-personal
# copy one account's public key to clipboard
sshgit account copy-pub github-personal
# wire the current repo to an alias
sshgit repo use github-work
# repo wiring example (origin -> alias host)
git remote add origin git@github.com:samyou/sshgit.git
sshgit repo use github-work
git remote get-url origin
# git@github-work:samyou/sshgit.git
# remove an alias and its key files
sshgit account remove --alias github-personal --delete-key# run from source
bun run dev -- --help
# typecheck
bun run typecheck
# bundle CLI for publishing
bun run build
./dist/sshgit.js --helpOptional local install:
mkdir -p "$HOME/.local/bin"
cp ./dist/sshgit.js "$HOME/.local/bin/sshgit"
chmod +x "$HOME/.local/bin/sshgit"Then use:
sshgit --helpRun from source:
bun run dev -- <command>Run compiled binary:
./dist/sshgit.js <command>Initialize managed files and SSH include:
bun run dev -- initAdd an account (creates key, updates ~/.ssh/sshgit_config, stores metadata):
bun run dev -- account add \
--provider github \
--account work \
--email you@company.com \
--git-name "Your Name"List accounts:
bun run dev -- account listTest SSH auth:
bun run dev -- account test
# or
bun run dev -- account test github-workCopy public key to clipboard:
bun run dev -- account copy-pub github-work
# if only one account exists, alias is optional
bun run dev -- account copy-pubUse an account in the current repo (rewrites remote + sets local git identity):
bun run dev -- repo use github-workExample flow for repo use:
# start with a normal GitHub SSH remote
git remote add origin git@github.com:samyou/sshgit.git
# rewrite origin to your sshgit alias host
bun run dev -- repo use github-work
# origin is now wired to the alias host
git remote get-url origin
# git@github-work:samyou/sshgit.gitRemove an account:
bun run dev -- account remove --alias github-work
# optionally also delete key files
bun run dev -- account remove --alias github-work --delete-key- Generated keys default to
~/.ssh/id_ed25519_<provider>_<account>. - Managed SSH config lives in
~/.ssh/sshgit_configand is included from~/.ssh/config. - After
account add, runsshgit account copy-pub <alias>and paste the key into your provider settings page.
MIT