Score:0

Match different subpath in SSH config

do flag

I need to set a configuration for SSH keys related to the same domain but different subpath. I'd like to have something like:

Host                domain.com/sub1
    Hostname        domain.com/sub1
    User            user1
    IdentityFile    ~/.ssh/key1

Host                domain.com/sub2
    Hostname        domain.com/sub2
    User            user2
    IdentityFile    ~/.ssh/key2

so that when I do git clone domain.com/sub1... it uses ~/.ssh/key1 while when doing git clone domain.com/sub2... it uses ~/.ssh/key2.

How can I do that without changing the git repositories' configurations?

Thanks

Score:0
in flag

SSH does not have a concept of "subpath" (as it cares only about server access), so you cannot configure it the way you want. You can use a Match entry, which matches the remote host and the remote user, but you cannot match any path element, as SSH cannot have knowledge about what you will access once the connection is established.

A Match entry matching hosts and users is something like this:

Match user="user1" host="domain.com"
  IdentityFile ~/.ssh/key1

Match user="user2" host="domain.com"
  IdentityFile ~/.ssh/key2

It practically works the way your config does, but "user2" on "domain.com" will use "key2" regardless of the repository you try to access.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.