Reputation: 779
I have 2 accounts that I want to use with Github, and I am trying to set up github to work on multiple accounts via ~/.ssh/config by following this tutorial. I created 2 ssh keys (for example rsa_1 and rsa_2) and set up the ~/.ssh/config file like this:
Host github.com
HostName github.com
User username1
IdentityFile ~/.ssh/id_rsa_1
IdentitiesOnly yes
Host work.github.com
HostName github.com
User username2
IdentityFile ~/.ssh/id_rsa_2
IdentitiesOnly yes
then, I set the remote url on the repo I want to use with another account with
git remote set-url origin work.github.com:<shared_gitrepo_name>/project.git
but when I git push origin, it always times out with
ssh: connect to host work.github.com port 22: Operation timed out
fatal: Could not read from remote repository.
which makes me think that the config file isn't being referenced. I am not sure what I am doing wrong. Any help would be appreciated!
Upvotes: 1
Views: 2706
Reputation: 1324537
You are using the wrong Username in both cases:
Host github.com
HostName github.com
User git <==========================
IdentityFile ~/.ssh/id_rsa_1
IdentitiesOnly yes
Host work.github.com
HostName github.com
User git <==========================
IdentityFile ~/.ssh/id_rsa_2
IdentitiesOnly yes
You always ask for an SSH sesssion to github.com as user "git
", not user "usernamex
".
The fact your public key is copied to username1
or username2
SSH profile page will be enough for GitHub to know who you are.
But, as phd note in the comments, a timeout might indicate a network connection issue (like a firewall blocking the outgoing traffic on port 22).
Even if that was working, then the wrong user would fail the ssh call anyway.
Note: as seen in the discussion, don't use sudo
Using sudo
means only /etc/shh/config
will be considered, not ~/.ssh/config
Upvotes: 1