Skip to content

Instantly share code, notes, and snippets.

@andreibosco
Created October 29, 2024 02:39
Show Gist options
  • Save andreibosco/91ed55dee4c2bca7645244cb51ec5269 to your computer and use it in GitHub Desktop.
Save andreibosco/91ed55dee4c2bca7645244cb51ec5269 to your computer and use it in GitHub Desktop.
Multiple ssh identities with 1password

Source: https://1password.community/discussion/130911/chosing-which-ssh-key-to-use

  1. Download the public key for both SSH key items:

share-public-key

  1. Move the public keys to your ~/.ssh/ directory.

  2. Configure hosts for your personal and work GitHub profile by appending the following to your ~/.ssh/config:

# Personal GitHub
Host personalgit
  HostName github.com
  User git
  IdentityFile ~/.ssh/personal_git.pub
  IdentitiesOnly yes

# Work GitHub
Host workgit
  HostName github.com
  User git
  IdentityFile ~/.ssh/work_git.pub
  IdentitiesOnly yes

Make sure the IdentityFile matches the names of the files at step 2.

  1. For each repo, change the git URL to use one of the new hosts instead of [email protected]:
git remote set-url origin <host>:<workplace>/<repo>.git

For example:

git remote set-url origin personalgit:1password/1password-teams-open-source.git

Now your SSH clients will know which SSH key to use for each repository and the right GitHub account will be used for each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment