Issue
I have this setup in .ssh/config
. Every time I do a git push it will says permission deny.
My 1st question is that what exactly is Host
and HostName
?
2nd question is that if I change bitbucket_personal
to bitbucket.org
and bitbucket_work
to bitbucket.org
. bitbucket_work
(the last one in config) will always work, no permission denied issue. Is it a way to make the following config work?
Host bitbucket_personal
HostName bitbucket.org
User kenpeter
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Host bitbucket_work
HostName bitbucket.org
User kenpeter_work
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_work
Solution
My 1st question is that what exactly is Host and HostName?
Host
and HostName
are SSH options.
The first one initiates conditional block (as illustrated by the indentation) and is matched against the host that is written on command-line or in the clone URL. It can be also understood as an alias.
The HostName
is basically overwriting that alias with a real hostname so you are going to end up connecting to the correct server, even if you write ssh -vT git@bitbucket_personal
.
2nd question
Well ... obviously. You need to adjust the clone/push/pull URLs in the git
to reflect this. Basically for clonning personal repositories, you will need to replace bitbucket.org
with bitbucket_personal
and for work ones accordingly with bitbucket_work
. For existing repositories, do the same in the .git/config
, where you can find it on several lines.
Answered By - Jakuje Answer Checked By - Dawn Plyler (WPSolving Volunteer)