using multiple ssh key to access gitolite

(This is my personal memo.. More beautiful solutions could be found on the web.)

Using gitolite without adding oneself into @admin (or gitolite-admin), we need to use two keys (my own and one of gitolite account) for accessing gitolite repository. Even using ssh-agent (and only your own key added), specifying key for gitolite using ‘ssh://somehost-with-gitolite/gitolite-admin’ (and .ssh/config) will work.

% git clone ssh://somehost-with-gitolite/gitolite-admin
Cloning into gitolite-admin…
remote: Counting objects: 48, done.
remote: Compressing objects: 100% (38/38), done.
remote: Total 48 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (48/48), 5.24 KiB, done.
Resolving deltas: 100% (9/9), done.

On this server, I have two access: one with my own key (and user name ‘himorin’), another with gitolite admin key. And gitolite-admin is only accessible by gitolite key. Also for my local, I have added only my own key (like id_rsa) to ssh-agent, but not for gitolite key.

After initial clone, when ‘git pull’, it does not work. And it seems git uses my own key (from command line output).

% git pull ssh://somehost-with-gitolite/gitolite-admin
R access for gitolite-admin DENIED to himorin
fatal: The remote end hung up unexpectedly

Two solutions found on this:

  • Simply adding my own key to gitolite-admin repo.
  • Add gitolite key into ssh-add, or disable ssh-agent (or delete SSH_* ENV) on the shell

Of course, .git/config says

[remote “origin”]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://somehost-with-gitolite/gitolite-admin

Leave a Reply »