Skip to content

[FR] Add ability to connect to a single host using different keys per repo/remote #1455

@tp-woven

Description

@tp-woven

At work, we are migrating to use GitHub's Enterprise Managed Users (EMU), and our enterprise policy prevents enterprise users from interacting with non-enterprise repos (no PRs, no commenting on issues, etc.). So in order to contribute to OSS, we have to maintain two separate users - an enterprise one and a public one. This causes a problem when using SSH keys to authenticate - GitHub does not allow the same key to be used for multiple users, so each user has to have its own SSH key.

This then brings up the question of how to choose which key to use when connecting to github.com. With Git, it respects ~/.ssh/config, so the following setup works (just have to remember to use the appropriate host in remotes):

Host github
  HostName github.com
  User tp-woven
  IdentityFile ~/.ssh/id_ed25519
  AddKeysToAgent yes
  IdentitiesOnly yes

Host github-sg
  HostName github.com
  User <enterprise_user>
  IdentityFile ~/.ssh/id_ed25519_emu
  AddKeysToAgent yes
  IdentitiesOnly yes

However, trying to use this setup with jj results in an error:

Error: failed to resolve address for github-sg: nodename nor servname provided, or not known; class=Net (12)

@yuja suggested on Discord that I may be able to use ssh-add -h, but this does not seem to be supported on macOS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions