1

I am opening some question I somewhat asked before but now the problem seems to be pretty linked to ssh.

  1. I have installed Gitlab in /home/myuser/gitlab.
  2. I created a rep test
  3. Following instructions, I added a remote git@localhost:root/testing.git (Gitlab's server runs on port 3000)

Now, when I try to push, I get this error message:

$ git push -u origin master
    ssh: Could not resolve hostname mylocalhost: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Now, I found that there was a problem with my ssh connect. Here's my /home/myhome/.ssh/config file

Host mylocalhost
Hostname localhost
PORT 3000
User git
IdentityFile /home/myuser/.ssh/id_rsa.pub

When I run ssh mylocalhost I get this message

ssh_exchange_identification: Connection closed by remote host

On verbose mode, it seems that the connection is established on the right port but the porcess fails here debug1: ssh_exchange_identification: HTTP/1.1 400 Bad Request. I tried to update my /System/Library/LaunchDaemons/ssh.plist (I am using OSX) to forward port listening to 3000 but then the Gitlab Webrick Rails server won't run anymore. L tried to change git remote set-url origin mylocalhost:testing.git

epsilones
  • 11,279
  • 21
  • 61
  • 85
  • possible duplicate of [git remote add with other ssh port](http://stackoverflow.com/questions/3596260/git-remote-add-with-other-ssh-port) – Joe Jul 19 '13 at 13:27

3 Answers3

0

Gitlab's HTTP interface is probably running on port 3000, but SSH isn't running there to push the repository to.

The message of ssh: connect to host localhost port 22: Connection refused means that the SSH client was unable to connect to the SSH server at localhost on port 22. I'd ensure you've installed gitlab correctly and Gitlab is running correctly. Also ensuring the ssh server is running and able to accept connections on port 22.

Steven V
  • 16,357
  • 3
  • 63
  • 76
0

You cannot hope to use the port 3000 if you are using a fully specified url

 git@localhost:root/testing.git

As I have explained to you before:

The idea of the ssh config file is to define an entry "foobar" which will set the right server name (Hostname), ssh private key (IdentityFile), and user under which the ssh session is opened.
That would allow to do 'ssh foobar' (without having to put git@xxx, and with non-standard public/private keys files).
You can define as many entry as you want, allowing you to use different user and keys.

So you cannot define origin with git@xxx. You must type:

git remote add origin mylocalhost:testing.git 

Or, if origin is already defined, and you need to change its url:

git remote set-url origin mylocalhost:testing.git 

(no 'root/' you don't specify any path in front of a gitlab repo: gitlab will deduce the full path of the repo)

But you need to be sure your sshd starts on port 3000, and that gitlab.yml contains that port number.


ssh: Could not resolve hostname mylocalhost: nodename nor servname provided, or not known

That means ssh cannot find ~/.ssh/config, with a mylocalhost entry in it.
Make sure that file exist.

Your previous question put in ~/.git/config, which has nothing to do with ssh.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • sorry, I had a copy paste pb, the error message is no longer the same. In fact, when I change the `sshd` port as explained here: http://serverfault.com/questions/18761/how-to-change-sshd-port-on-mac-os-x, my `Webrick` `Rails` server won't no longer run ... – epsilones Jul 19 '13 at 13:54
  • Sure I have it (I also verufy `sudo` user can see it). Here's how it is Host mylocalhost Hostname localhost PORT 3000 User git IdentityFile /home/myuser/.ssh/id_rsa.pub` Btw, when I launch `ssh -v mylocalhost`, the connection is established with the right `HOSTNAME` and in the right `PORT` – epsilones Jul 19 '13 at 14:14
  • @Newben What `git remote -v` returns within the repo you are trying to push to origin? And on the gitlab side, does a `sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production` complete successfully? – VonC Jul 19 '13 at 14:34
  • the result of the first request is 'origin mylocalhost:testing.git (fetch) origin mylocalhost:testing.git (push)' and the second completes successfully – epsilones Jul 19 '13 at 14:45
  • in fact, I have `.ssh` `config` file is in `/home/myhome/`, but `GitLab` is running under `/home/myuser`. Should I add a `.ssh` `config` file under `/home/myuser` ? – epsilones Jul 20 '13 at 09:32
  • @Newben gitlab should be running in the exact account proposed by the **[setup documentation](https://github.com/gitlabhq/gitlab-ci/blob/master/doc/installation.md): `git`. Your ssh config is for your client account to use, and has nothing to do with the account running gitlab. It is a convenient way to use a "simpler" ssh url `mylocalhost:testing.git` instead of `git@yourserver:3000/testing.git`. – VonC Jul 20 '13 at 09:36
  • Ok, things are changing now I deleted the `PORT 3000` line in my `.ssh/config` and now `ssh mylocalhost` works just well. But when I run `git push -u origin master` I am said that `fatal: 'testing.git' does not appear to be a git repository` I thing only `sudo` can see the repo. But when I run `sudo git push -u origin master`, I get `ssh: Could not resolve hostname mylocalhost`. In fact, `sudo ssh mylocalhost` fails, because it doesn't seem to fetch data from `ssh` `config` file. Should I add config lines into `/opt/local/etc/ssh/ssh_config` ? – epsilones Jul 20 '13 at 09:54
  • @Newben I confirm a `sudo git push` could not possibly work: you clone, push pull as *a client*: `yourhome`. Not as `root` (again, forget `root`, you only need `sudo` in the gitlab setup). `sudo` will execute command as `root`, which has not an ssh config file like your account (and shouldn't have). – VonC Jul 20 '13 at 09:58
  • In fact, I notice that `ssh mylocalhost` connects me to `/home/myuser`, and not in `/home/myuser/gitlab`. But `git remote set-url origin mylocalhost:gitlab/testing.git` won't change the output of `git push -u origin master` fatal: 'gitlab/other.git' does not appear to be a git repository. Btw, it seems I should add again `PORT 3000` in my ssh config file, but then I still get `ssh_exchange_identification: Connection closed by remote host` when I push. What a mess !;) So when you said `make sure your sshd starts on port 3000`, how to do it on `osx` ? I tried a lot of things, but none worked – epsilones Jul 20 '13 at 10:52
  • @Newben I agree. At this point, try to simply redo the all setup process, following *exactly* the convention (in term of accounts) proposed in it. No need for port 3000. – VonC Jul 20 '13 at 10:52
0

At last, I figured out what was the problem. I had to set properly the ~/.ssh/config file

 Host mylocalhost
    Hostname localhost
//I deleted a line specifying the PORT to 3000
    User git
    IdentityFile /home/myuser/.ssh/id_rsa //It was previously set to /home/myuser/.ssh/id_rsa.pub

Then I reinstalled a key but I still got some problem. Finally, setting the perm of the file /home/myuser/.ssh/id_rsa to 644 and it worked just fine. For information, I found searching in the web that some settings could work with a 700 or a 600 chmod perm, but for me 644 did the trick

epsilones
  • 11,279
  • 21
  • 61
  • 85
  • 2
    Sounds good. I have written before about permissions for ssh files: http://stackoverflow.com/a/3712619/6309 – VonC Jul 20 '13 at 19:45