4

I have my own gitlab setup on my own domain. I have been using it happily from my windows desktop, using gitbash. I have been creating repos via the Gitlab web front end then pushing my codebase from my local machine like so;

git remote add origin gitlab_user@my.gitlab.domain:my_namespace/my_repo.git

I can also clone, like this;

git clone gitlab_user@my.gitlab.domain:my_namespace/my_repo.git my_repo

No problems doing either of these on my desktop.

If I try and do the same from centOS box (the same one that hosts my gitlab domain, though it may not always be) I am prompted for the gitlab_user password. After this, the same clone command tells me that my_namespace/my_repo.git does not appear to be a git repository. I know it is because it I have no problems accessing it from my windows machine.

Any ideas why it isn't seeing it as a repo when I connect from elsewhere, and why is it asking for the password?

charliefortune
  • 3,072
  • 5
  • 28
  • 48
  • is the ssh key/identity from the centos box added to gitlab, and allow access to your repos? – Doon Sep 04 '13 at 12:24
  • I am unsure which user to add it to. I believe that I have to connect to my gitlab as gitlab_user, then am I right in thinking that gitlab identifies me from what is in my key? – charliefortune Sep 04 '13 at 13:45
  • gitlab uses gitolite under the hood. You need to add the the identity key from the centos box into gitlab (i think you do this via the gui). and then it will allow access. – Doon Sep 04 '13 at 13:55
  • I'm using gitlab 5.x which doesn't use gitolite any more. – charliefortune Sep 04 '13 at 15:56

2 Answers2

4

The Solution

In conclusion, it was indeed because I did not have my .ssh public key added to the user account in gitlab. The steps to fix this were;

  1. ssh onto my linux box as the user I want to clone as. I have created a user specially for this purpose.
  2. ssh-keygen -t rsa -C "newuser@my.domain.com" - (The -C part is a comment that helps me work out whose key this is if I ever forget.)
  3. Copy the contents of the public key (whilst still logged into linux box as my new user) with cat ~/.ssh/id_rsa.pub
  4. Log into gitlab (as a user who has permission to access the project that you want to clone) and add this ssh key to the account, by pasting the public key that you just copied in step 4.

Now I can clone using my original command;

git clone gitlab_user@my.gitlab.domain:my_namespace/my_repo.git my_repo

What I Learned

I will always initially connect to my gitlab server as user gitlab_user. But upon arrival, gitlab will identify which user account I am claiming to be by matching my public key with one stored against one of the accounts it has in its database. That's why you can't attach the same .ssh key to more than one gitlab account - gitlab wouldn't know who you were when you connected.

However, you can put more than one (different) key on a single account. For example, I need to be able to access the repo from home and from the office, but be identified as the same gitlab user each time. I do this by creating as .ssh key at home and adding it to my gitlab account, and doing the same at work. Two different keys, identifying me as the same gitlab user.

charliefortune
  • 3,072
  • 5
  • 28
  • 48
  • +1 good feedback. This seems similar to the general idea I mentioned in [my own answer](http://stackoverflow.com/a/18614443/6309). – VonC Sep 04 '13 at 15:40
  • It is (+1). I only answered this myself to provide a sort of beginners answer to the problem in hand without the distraction of /.ssh/config file. Although I do like the config file option too and am investigating it now. I won't accept any answer just yet, I hope you don't mind. – charliefortune Sep 04 '13 at 15:48
1

Check if you do have an ssh key in your centOs ~/.ssh, but if you don't, I wouldn't advise to copy the ones on your windows %HOME%/.ssh.

Generate a new pair of keys, and register your public ssh key in the GitLab ssh config page.
You can see an example in this gitlabhq-recipe script

ssh-keygen -q -N '' -t rsa -f ~/.ssh/id_rsa

I like to start with a key without a passphrase first:

ssh-keygen -t rsa -f "$HOME/.ssh/gitlab" -C "GitLab access (not interactive)" -q -P ""

But in the case of a non-conventional name, I add a ~/.ssh/config file:

Host gilab
    HostName my.gitlab.domain
    User gitlab_user
    IdentityFile ~/.ssh/gitlab

In that case, instead of cloning gitlab_user@my.gitlab.domain:my_namespace/my_repo.git, I can clone:

git clone gitlab:my_namespace/my_repo.git
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250