1Password Github setup

1Password Git setup

**Not really a 1password thing, but 1password can do lookups in the vault, though sequentially throughout all keys which might timeout before it gets to the one you want. **

SSH keys with multiple repositories and accounts

Notice! The official docs are incorrect, they state that you should download the Public key from your vault to use multiple Github accounts https://developer.1password.com/docs/ssh/agent/advanced but you should instead download the privatekey. (Since you cant authenticate your public key with the public key in your github account)

  1. Download each private key file to ~/.ssh and rename appropriately. Named mine work_git.key and personal_git.key

  2. edit OR create ~/.ssh/config

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

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

This will setup

HostName for which we will need later User is always git for Github SSH keys IdentityFile the identityFile, the private key

  1. In each repository you have, check which remote you have. For the repo behind this wiki, I have

git remote -v
origin  https://github.com/qhrizz/wiki.git (fetch)
origin  https://github.com/qhrizz/wiki.git (push)
  1. Change this to the new "host"

git remote set-url origin personalgit:qhrizz/wiki.git  

where personalgit comes from the HostName in the config file

Checking the remote now shows

git remote -v
origin  personalgit:qhrizz/wiki.git (fetch)
origin  personalgit:qhrizz/wiki.git (push)

Test to pull and it should work.


Clone a new repo using the key

ssh-add ~/.ssh/personal_git.key; git clone git@github.com:qhrizz/wiki.git

Or

git clone git@github.com:qhrizz/wiki.git --config core.sshCommand="ssh -i /Users/qhrizz/.ssh/personal_git.key"

And it should clone without any issues and then you can set the remote with

git remote set-url origin personalgit:qhrizz/wiki.git  

Last updated