I am trying to setup my git config to choose the ssh that corresponds to each case
Host github.com_enterprise
Hostname github.com
User [email protected]
IdentityFile ~/.ssh/id_enterprise_ssh
Host github.com_personal
Hostname github.com
User [email protected]
IdentityFile ~/.ssh/id_personal_ssh
or
Host github.com:enterprise
Hostname github.com
User [email protected]
IdentityFile ~/.ssh/id_enterprise_ssh
Host github.com:personal
Hostname github.com
User [email protected]
IdentityFile ~/.ssh/id_personal_ssh
I have found that the host was supposed to be the alias but it doesn't work. For example, if want to make git clone works with id_enterprise_ssh what I have to do is
Host github.com
Hostname github.com
User [email protected]
IdentityFile ~/.ssh/id_enterprise_ssh
I have to edit the host by deleting the _enterprise
and deleting the other github.com_personal
information. So, I wonder what I am missing in my config setup
CodePudding user response:
When you use ssh via something like git clone [email protected]:your-username/your-repo.git
, SSH is looking for github.com
to match the Host <X>
alias, not the Hostname value. So, if you use the first option for ssh_config, your SSH-related commands should look like:
git clone [email protected]_personal:<org>/<repo>.git
Note that once you start doing this, you may have to make sure your remote-urls are configured correctly (that is, that they say github.com_personal
and github.com_enterprise
). You can check with git remote -v
. You also have to make sure all of the relevant SSH keys are added to your SSH-agent.
CodePudding user response:
Considering an SSH URL for github.com
will always use git@
as a remote user, do replace in each of your Host entry a line:
User git
That way, you can test each of your Host entry wtih
ssh -Tv github.com_personal
ssh -Tv github.com_enterprise
In both instances, you should see a welcome message with the right perosnal or enterprise username in it.