git Over A Non-Standard ssh Port

git speaks ssh over the standard port 22 out of the box, and flawlessly. For example:

git clone git@hostname:repository_name

There are a fair number of installations running ssh on non-standard ports, however, and the above method doesn’t directly support a port, it seem. Linux Torvald answered the the question back in 2005, and suggested editing the local ssh config file. This works beautifully where Un*x is spoken, including Mac OS X.

In the ~/.ssh/config file add an entry such as:

Host host_alias
    User git
    Port port_number
    Hostname hostname

For those poor souls in Windows land, Mauvis Ledford has a tip:

$ git clone ssh://user@host:port/repository

should work also.

One thought on “git Over A Non-Standard ssh Port

  1. Pingback: Gitosis cloning out on non-default port | PHP Developer Resource

Leave a Reply