Skip to content

Instantly share code, notes, and snippets.

@kulcsarrudolf
Created April 20, 2026 05:04
Show Gist options
  • Select an option

  • Save kulcsarrudolf/e98b3dcd9a6265787a3863e70f9dfeb5 to your computer and use it in GitHub Desktop.

Select an option

Save kulcsarrudolf/e98b3dcd9a6265787a3863e70f9dfeb5 to your computer and use it in GitHub Desktop.
Claude Code skill: set up SSH keys for multiple Git accounts (GitHub, Bitbucket, GitLab)
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".

Set up multiple Git accounts in one go

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.

Step 1. Ask for the account list

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

platform is one of: github, bitbucket, gitlab.

Parse each line into {label, platform, email}. If the format is wrong, show the example again.

Step 2. Generate one SSH key per account

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".

Step 3. Write ~/.ssh/config

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 github account uses Host github.com (the default).
  • Every other github account uses Host github-<label>.
  • First bitbucket account uses Host bitbucket.org. Others use Host bitbucket-<label>.
  • First gitlab account uses Host gitlab.com. Others use Host 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".

Step 4. Register each public key on the platform

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"   # Linux

Per 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. Usage Authentication & Signing.

After the user confirms they added the key, move to the next account.

Step 5. Verify each alias authenticates

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.

Step 6. Turn on commit signing

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 true

For 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"

Step 7. Show how to clone

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

Rules you must follow

  • One key per account. Never reuse.
  • Always set IdentitiesOnly yes.
  • Always back up ~/.ssh/config before writing.
  • Never commit or print private keys. Only .pub files are safe to share.
  • ~/.ssh must be mode 700. ~/.ssh/config must be mode 600.
  • Do not push anywhere without the user's explicit ok.

Troubleshooting

  • "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.signingkey points to the wrong file, or commit.gpgsign is off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment