master TOC | chapter TOC | support
(or "making git use the right options for ssh")
The ssh command has several options for non-default items to be specified.
Two common examples are -p for the port number if it is not 22, and -i for
the public key file if you do not want to use just ~/.ssh/id_rsa or such.
Git has two ssh-based URL syntaxes, but neither allows specifying a
non-default public key file. And a port number is only allowed in one of
them. (See man git-clone for details). Finally, hosts often have to be
referred with IP addresses (such is life), or the name is very long, or hard
to remember.
Using a "host" para in ~/.ssh/config lets you nicely encapsulate all this
within ssh and give it a short, easy-to-remember, name. Example:
host gitolite
user git
hostname a.long.server.name.or.annoying.IP.address
port 22
identityfile ~/.ssh/id_rsa
Now you can simply use the one word gitolite (which is the host alias we
defined here) and ssh will infer all those details defined under it -- just
say ssh gitolite and git clone gitolite:reponame and things will work.
(By the way, the 'port' and 'identityfile' lines are needed only if you have non-default values, although I put them in anyway just to be complete).
If you have more than one pubkey with access to the same server, you must use this method to make git pick up the right key. There is no other way to do this, as far as I know.