Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I use a non-standard ssh port (1234) for most of the servers I connect to. So in my ssh config file I have:

Port 1234

But github.com uses port 22. When I try to connect to github it obviously tries to use port 1234. Right now I have to edit my ssh config to get things to work.

Here is a snippet from my git config:

[remote "origin"]
        url = git@github.com:asdf/asdf.git
share|improve this question

3 Answers 3

up vote 9 down vote accepted

Just have a look at how to set up your ~/.ssh/config file correctly (man 5 ssh_config). You can specify different settings for different hosts easily. To solve your problem you would set

Host github.com
Port 22
Host *
Port 1234

Do have a look at the ssh_config manual page, it explains everything you need to know on the first few pages.

share|improve this answer

Setting up a section in ~/.ssh/config is a fine solution, but it may be useful to know about another method.

The common scp-like syntax of user@host:path does not have a place for a port, but Git also supports an ssh: URL scheme that can be used to specify the port:

ssh://git@github.com:22/asdf/asdf.git

While an ssh: URL supports port specification, it does not support relative paths (e.g. there is no direct equivalent to the scp-like syntax of user@host:path where path does not start with a slash).

GitHub treats relative and absolute paths identically, so it works for them, but it may not work for all SSH-based Git repositories. For simple SSH-based hosting, you may need to insert /home/username/ or /Users/username/ when switching from relative to absolute paths. Some hosting systems may not handle absolute paths at all (though I would tend to call such lack of support a bug).

share|improve this answer
    
Thanks Chris. I like this path best because it doesn't require mucking with my ssh config. Thanks! –  James Ward Jan 5 '11 at 15:17
    
fyi, if the server has a "bare" repo then the connection string would look more like ssh://git@github.com:22/asdf/asdf (without the .git) –  Xeoncross Jan 23 '11 at 19:06

(Love it when I find the answer right after asking it.)

I modified my ssh config to specify the port for each host instead of being a global setting:

Host asdf.com
    Port 1234

Host github.com
    User git
    Hostname github.com
    Port 22
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.