| name | setup-multi-git-ssh |
|---|---|
| description | Set up SSH keys for multiple Git accounts in one shot. Ask the user for their account emails and labels, then generate keys, write ~/.ssh/config, guide them through adding each key to the right platform, and turn on commit signing. Use when the user says "set up my Git SSH keys", "I have two GitHub accounts", "I need to use Bitbucket and GitHub together", or sees errors like "Key is already in use" or "Please make sure you have the correct access rights". |
You are the agent. The user wants a working multi-account SSH setup with minimal effort. Ask for the account list, then do the work.
Ask one question and wait for the answer:
Give me your accounts, one per line, in this format:
<label> <platform> <email>Example:
personal github me@personal.com work github me@company.com work-bb bitbucket me.work@company.com
platformis one of:github,bitbucket,gitlab.
Parse each line into {label, platform, email}. If the format is wrong, show the example again.
For every account, run:
ssh-keygen -t ed25519 -C "<email>" -f "$HOME/.ssh/id_ed25519_<label>" -N ""Use no passphrase unless the user asks for one. Never reuse a key across accounts. GitHub and Bitbucket both reject it with "Key is already in use".
Back up the existing file first, then generate the config.
[ -f "$HOME/.ssh/config" ] && cp "$HOME/.ssh/config" "$HOME/.ssh/config.backup.$(date +%Y%m%d%H%M%S)"For each account, pick a host alias:
- First
githubaccount usesHost github.com(the default). - Every other
githubaccount usesHost github-<label>. - First
bitbucketaccount usesHost bitbucket.org. Others useHost bitbucket-<label>. - First
gitlabaccount usesHost gitlab.com. Others useHost gitlab-<label>.
Block template:
Host <alias>
HostName <github.com | bitbucket.org | gitlab.com>
User git
IdentityFile ~/.ssh/id_ed25519_<label>
IdentitiesOnly yes
IdentitiesOnly yes is required. Without it, SSH offers every key and the host locks the connection.
Finish with chmod 600 "$HOME/.ssh/config".
For every account, copy the public key to the clipboard and tell the user where to paste it:
pbcopy < "$HOME/.ssh/id_ed25519_<label>.pub" # macOS
# or: xclip -sel clip < "$HOME/.ssh/id_ed25519_<label>.pub" # LinuxPer platform:
- GitHub: open
https://github.com/settings/ssh/new. Add the key twice: once as Authentication Key, once as Signing Key. Both slots are separate entries. - Bitbucket: open
https://bitbucket.org/account/settings/ssh-keys/. Add the key once. - GitLab: open
https://gitlab.com/-/user_settings/ssh_keys. UsageAuthentication & Signing.
After the user confirms they added the key, move to the next account.
For every alias, run:
ssh -T git@<alias>Expect a greeting with the matching account name. If it fails with "Permission denied (publickey)", the key is not registered on that account or the IdentityFile path is wrong.
Set the personal account as the global signing key:
git config --global user.signingkey "$HOME/.ssh/id_ed25519_<personal-label>.pub"
git config --global gpg.format ssh
git config --global commit.gpgsign trueFor every other account, tell the user to run this inside each of their repos for that account:
git config user.signingkey "$HOME/.ssh/id_ed25519_<label>.pub"Print a quick reference the user can keep:
Clone commands:
git clone git@<alias>:<org>/<repo>.git
Change remote on an existing repo:
git remote set-url origin git@<alias>:<org>/<repo>.git
- One key per account. Never reuse.
- Always set
IdentitiesOnly yes. - Always back up
~/.ssh/configbefore writing. - Never commit or print private keys. Only
.pubfiles are safe to share. ~/.sshmust be mode700.~/.ssh/configmust be mode600.- Do not push anywhere without the user's explicit ok.
- "Key is already in use": the public key is on another account. Generate a new key for the new account.
- "Permission denied (publickey)": the key for that alias is not registered as Authentication Key, or the remote URL uses the wrong host alias.
- "Please make sure you have the correct access rights and the repository exists": same as above, or the signing key was confused with the auth key. Check the remote URL.
- Commit shows "Unverified": the public key is not registered as a Signing Key, or
user.signingkeypoints to the wrong file, orcommit.gpgsignis off.