Skip to content

Instantly share code, notes, and snippets.

@giordanocardillo
Last active May 9, 2017 10:57
Show Gist options
  • Save giordanocardillo/ec30a3ea297d358b557b001f411379ed to your computer and use it in GitHub Desktop.
Save giordanocardillo/ec30a3ea297d358b557b001f411379ed to your computer and use it in GitHub Desktop.
Using SSH with git

Put in your .git/config

[remote "origin"]
        ...
        url = ssh://git@gitolite-as-alice/my-repo
        ...

Even if the user and host are the same, they can still be distinguished in ~/.ssh/config. For example, if your configuration looks like this:

Host gitolite-as-alice
  HostName git.company.com
  User git
  IdentityFile /home/whoever/.ssh/id_rsa.alice
  IdentitiesOnly yes
  CheckHostIP no
  StrictHostKeyChecking no

Host gitolite-as-bob
  HostName git.company.com
  User git
  IdentityFile /home/whoever/.ssh/id_dsa.bob
  IdentitiesOnly yes
  CheckHostIP no
  StrictHostKeyChecking no

Then you just use gitolite-as-alice and gitolite-as-bob instead of the hostname in your URL:

git remote add alice git@gitolite-as-alice:whatever.git
git remote add bob git@gitolite-as-bob:whatever.git

Note

You want to include the option IdentitiesOnly yes to prevent the use of default ids. Otherwise, if you also have id files matching the default names, they will get tried first because unlike other config options (which abide by "first in wins") the IdentityFile option appends to the list of identities to try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment