Reputation: 31
I'm on my work computer, which is already [successfully] configured to connect to our GitHub account and authenticate our commits using SSH and GPG keys, respectively. Before I began changing things, my original ~/.ssh/config
file was this:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
To add my personal account, I generated a new SSH key (~/.ssh/id_rsa_personal
), added the .pub
part to my personal GitHub account, and modified my ~/.ssh/config
file to the following:
# Default
Host *
AddKeysToAgent yes
UseKeychain yes
# Personal
Host github.com-PERSONAL
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
# Work
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
After this change, I am still able to interact with my work account without a problem – nothing has changed. However, when I attempt to interact with my personal account using
git clone git@github-PERSONAL:nikblanchet/myrepository.git
, I am getting an error message:
Cloning into 'myrepository'...
ssh: Could not resolve hostname github-personal: nodename nor servname provided, or not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
To narrow down the issue, I decided to try a simple SSH authentication
ssh -T [email protected]
, and, surprisingly, it worked!
Hi nikblanchet! You've successfully authenticated, but GitHub does not provide shell access.
(Running ssh -T [email protected]
authenticated with my work account, as expected.)
So now I'm lost. Why can ssh -T
resolve the hostname while git clone
cannot? What did I miss?
Upvotes: 3
Views: 125
Reputation: 1323095
You URL should be:
github.com-PERSONAL:nikblanchet/myrepository.git
You tried first
git@github-PERSONAL:nikblanchet/myrepository.git
That is why it was not able to resolve github-PERSONAL
, which is not in your config file.
github.com-PERSONAL
is.
Note: no need to add the git@
part: your config file does specify the User git
already.
Upvotes: 1