Reputation: 69
Firstly I would like to give context: I was trying to set my git and my ssh in ubuntu to handle multiple accounts (work, personal-study and personal projects). Following some tutorials, I wrote in my ssh the configuration for each type of connection. The next is the example of the configuration for the work account (inside config file in .ssh/)
Host work.github.com
HostName github.com
IdentityFile ~/.ssh/id_ed_work
User git
IdentitiesOnly yes
From the github repository I got an ssh URI
git@github.com:my_work_username/name_repository.git
I was having trouble making them work together up until I changed the URI provided by github at the moment of adding it as the remote of my local repository. I had to change it to the format:
git@work.github.com:my_work_username/name_repository.git
When using the command git remote add, so it matched the format I had given in the ssh file (in the line of Host). First, I didn't know you could manually change the URI provided by github, secondly, even though I have found sources like this one, I have been having trouble understanding what each part of an ssh URI does, what it refers to and why can I change that part without affecting the connection to my repository. I will thank any information and also sources to study more about server, hosts, will also be appreciated.
Upvotes: -1
Views: 52
Reputation: 531878
So first, the URI simply provides information about how to reach a given repository. You can provide that information in any way you like, as long as it is equivalent to the URI shown on GitHub.
Not terribly relevant, but worth remembering, is that git@github.com:my_work_username/name_repository.git
is an alternate form of the more proper URI ssh://git@github.com/my_work_username/name_repository.git
.
The URI provides the following bits of information:
ssh
will be used to connect to GitHub.git
, as whom you will authenticate. (Everyone is git
, but git
has many, many certificates associated with it, and access to repositories belong to git
is determined by which certificate git
chose to use to authenticate.)github.com
)my_work_username/name_repository.git
)If ssh
had no further configuration to go on, it would parse the URI and do the best it could. But you do provide further configuration, in the form of a block in your .ssh/config
file:
Host work.github.com
HostName github.com
IdentityFile ~/.ssh/id_ed_work
User git
IdentitiesOnly yes
This defines an alias, work.github.com
, to which you associate a "real" host name, an identity file, a user name, and an instruction to ignore identities from "outside" sources (like ssh-agent
; it's not worth going further into the meaning of this option here).
So instead of executing
ssh -i id_ed_work -o IdentitiesOnly=yes git@github.com:my_work_username/name_repository.git
using the "original" URI, you use the alias work.github.com
to execute the shorter command
ssh work.github.com:my_work_username/name_repository.git
Both commands use the same information provided by the original URI to connect.
Upvotes: 1