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?