3

I run Gitlab CE on my server and use several different user accounts to group my repos by interest. The problem is with SSH.

I found the following solution for github:

https://gist.github.com/jexchan/2351996

In this guide one just uses different hosts with the same hostname in the config. Which is little effort to achieve what I'd like to achieve. But this solution does not work with Gitlab or at least not for me.

This solution is all over the web. One that is less used but is working for me, is this one:

https://gist.github.com/gubatron/d96594d982c5043be6d4

In the second, one assigns subdomain names as hosts in the ssh config with the same hostnames and uses the same subdomains in the git config. Little example:

SSH config:

Host user1.git.mydomain.at
  HostName git.mydomain.at
  IdentityFile ~/.ssh/id_rsa_user1

Host user2.git.mydomain.at
  HostName git.mydomain.at
  IdentityFile ~/.ssh/id_rsa_user2

git:

git remote set-url origin admin@user1.git.mydomain.at:user1/foo.git
git remote set-url origin admin@user2.git.mydomain.at:user2/foo.git

One can see, that I have to change every repo url manually. I would like to avoid this, and would prefer the first solution.

Am I missing something important?

Richard Hansen
  • 51,690
  • 20
  • 90
  • 97
satanik
  • 572
  • 7
  • 21
  • `admin@`? shouldn't it be `git@`? – VonC Apr 21 '15 at 14:51
  • Usually it is git. But I do not own the server. So I could only use my own username, which is also the way the guide suggested setting it up. Has this anything to do with the question I posted? – satanik Apr 21 '15 at 14:55
  • If the urls are working, then it is ok. – VonC Apr 21 '15 at 14:59
  • As I stated in the question above. The urls are working. The git commands also work if I only use one of the ssh keys in the config. But with multiple I have problems. – satanik Apr 21 '15 at 15:46
  • I don't understand what you are asking. Both of the solutions you cite are the same, except for different naming conventions for the `Host`. Either solution should work equivalently, so if one is working and the other isn't then your question is missing some relevant information. – Richard Hansen Apr 29 '15 at 18:28
  • @RichardHansen They are not the same, as only the second one is working for me. I wrote everything down I did. So can you tell me what information you need to resolve my problem? – satanik Apr 30 '15 at 20:47
  • Both of the URLs you cite say to create two `Host` sections with bogus host names and `HostName` entries pointing to the real host. As far as I can tell, the only difference is the suggested name for the bogus host: the first URL suggests `-`, while the second suggests `.`. Given that the name provided for `Host` doesn't matter, these two approaches are equivalent. If the first doesn't work, please provide the detailed config you used and the error message(s). – Richard Hansen May 01 '15 at 15:15
  • Also, what do you mean by "I have to change every repo url manually"? – Richard Hansen May 01 '15 at 15:15

1 Answers1

2

You need both.

I Assuming that:

  1. usernames (not email) are user1 and user2 respectively

  2. you have uploaded adequate public (i.e. .pub) keys, for which the respective private keys are user1_rsa and user2_rsa

  3. the server url is in the form server.com (i.e. substitute server.com by bitbucket.org, github.com, etc.) then ~/.ssh/config should contain:

    Host server.com-user1
      HostName server.com
      User git
      IdentityFile ~/.ssh/user1_rsa
    
    Host server.com-user2
      HostName server.com
      User git
      IdentityFile ~/.ssh/user2_rsa
    

II. In your git directory, assuming that you have added an origin named origin and are in a domain named domain and a project named project, then git remote -v should be configured to return something like this:

origin  git@server.com-user1:domain/project.git (fetch)
origin  git@server.com-user1:domain/project.git (push)

  • You could have obtained this output in the first place by adding the remote directory using git remote add origin git@bitbucket.org-user1:domain/project.git. The key is the extra -user1, with a dash, matching in both files, and matching your username.
  • You can also edit .git/config after the fact and add -user1 by hand.
Community
  • 1
  • 1
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179