Score:0

Do not match Host * in ssh config if another rule was applied

cd flag

I have the following SSH config:

Host work.github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/work
    IdentitiesOnly yes

Host *
    IdentityFile ~/.ssh/personal

Where I want to use a work SSH key for a single repository by setting it's host to ssh://[email protected]:...

But what I think is happening is that the work SSH key is applied and host changed, but then the config is re-parsed with Host github.com and Host * now matches and re-sets the SSH key to my personal one

Here is a snippet from ssh -v [email protected]

OpenSSH_8.8p1, OpenSSL 3.0.8 7 Feb 2023
debug1: Reading configuration data /var/home/me/.ssh/config
debug1: /var/home/me/.ssh/config line 1: Applying options for *
// sets the correct SSH key
debug1: /var/home/me/.ssh/config line 4: Applying options for work.github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: configuration requests final Match pass
debug1: re-parsing configuration
debug1: Reading configuration data /var/home/me/.ssh/config
// Re-pases the file with Host: github.com and re-sets the SSH key
debug1: /var/home/me/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: Connecting to github.com [140.82.121.4] port 22.
debug1: Connection established.
...
Hi <PERSONAL>! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Connection to github.com closed.
Transferred: sent 2340, received 2404 bytes, in 0.4 seconds
Bytes per second: sent 5866.3, received 6026.7
debug1: Exit status 1

How can I handle this case?

jp flag
Reverse the order of Host entries. The wildcard should go the last.
Tc001 avatar
cd flag
Edited, it seems to have started randomly working again, I am unsure why or what I did. (but previously it didn't work both at the top or bottom)
jp flag
You can change wildcard to `Host * !work.github.com`
Score:0
im flag

You can use the "!" sign rule. For example:

Host work.github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/work
    IdentitiesOnly yes

Host * !work.github.com
    IdentityFile ~/.ssh/personal
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.