Using Git over non-standard SSH ports

I’ve configured some deployment servers to use SSH over non-standard SSH ports and that can really be a problem when you want to use that with git. No matter what you do, git would always attempt to connect through the standard SSH port 22.

There was really no point in scratching my head and trying to pull my hair out in order to fix this. So I googled a solution. This post gave me a hint but wasn’t helpful enough so I decided to write a blog post on how to go about solving this.

You’ll have to configure your repository in your .ssh/config file. Here’s an example. Simply substitute the #*# placeholders for the actual values

Host #hostname#
  User #username#
  Hostname #hostname#
  Port #non-standard port#

And if you prefer to use private keys to login:

Host #hostname#
  User #username#
  Hostname #hostname#
  Port #non-standard port#
  PreferredAuthentications publickey
  IdentityFile "#path_to_private_key#"

September 14, 2009

5 responses to Using Git over non-standard SSH ports

  1. Florian Vallen said:

    Thank you so much. You safed my time

  2. Josh Fraser said:

    Very helpful. Thanks for posting this.

  3. Tim said:

    @josh and @florian, thanks for your comments and welcome to my blog.

  4. exn said:

    Maybe is another solutions ?
    What you can suggest me if I have more than one repository via multiple logins and ports to the server ?

  5. Tilo said:

    there's really no need to put this in the .ssh/config file

    An easier way to do this is to set up your remote repository in Git the right way, e.g.:

    git remote add public ssh://username@node.youdomain.com:1234/home/username/GIT/Project.git

    that does the trick..

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>