Skip to main content
December 29, 2024
Question

1Password SSH Agent how to set specific ssh key

  • December 29, 2024
  • 2 replies
  • 2047 views

I have a few different ssh keys that are used for git and would like to have it set so that if going through one github organization i force one key if going to a personal account it uses a different key.

Is there any way as part of the IdentityAgent to specify the appropriate key or is the option just to keep cycling through the prompts for ssh keys?


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Browser: Not Provided

2 replies

Michael_Mercuri
January 17, 2025

You can specify which key to use for which host in ~/.ssh/config using IdentityFile option, where the identity file is the public key to use and the private key is stored in 1Password. You may also need to specify IdentitiesOnly yes.

Example for mailto:user99@example.com:


Host example.com
User user99
IdentityFile ~/.ssh/identity.pub
IdentitiesOnly yes

More here:
https://linux.die.net/man/5/ssh_config

jc00ke
March 11, 2025

I've been able to achieve this with git's conditional includes. Here's what a config may look like:

# ~/.config/git/config

[include]
    path = base-config.inc
[includeIf "hasconfig:remote.*.url:*:jc00ke/**"]
    path = personal-config.inc
[includeIf "hasconfig:remote.*.url:*:WORK/**"]
    path = work-config.inc

# ~/.config/git/personal-config.inc
[user]
    name = Jesse Cooke
    email = jesse@example.com
    signingkey = ~/.ssh/personal.pubkey

# ~/.config/git/work-config.inc
[user]
    name = Jesse Cooke
    email = jesse@work.example.com
    signingkey = ~/.ssh/work.pubkey

Here's my real dotfiles; this has worked for me for a while now.