Clone A Git Repository Using A Non-Standard Port

back to tech articles
Git 1.7, Cygwin, WAMP

I love Cygwin.

Ok, now thats out of the way. We want to clone our Git repository to the local machine. However, the savvy and security-conscious sysadmin dude has changed the default SSH port on the server. Here’s how we clone a repository through SSH on a non-standard port.

In case you didn’t already know, the standard SSH port is 22. Often server administrators will change this in a bid to improve security. Otherwise, anyone who can type ssh can have a million cracks at trying to break the root password. And, if they get in; well…

Change SSH Port

Not cool.

Launch Cygwin. Did I mention that I love Cygwin? Navigate to your sites directory. I will be breaking every rule in the geeks handbook of 2010 because I’m using WAMP. So, we do the following:

$ cd /cygdrive/c/wamp/www

Ok, we’re at our target directory. Normally, a Git clone request would look like this:

$ git clone user@ .

But, in our case that would eventually timeout and fail. That is because Git will hook into SSH and use it to connect to the remote host. A straight piggy-back. It will attempt to connect via the default port of 22 for SSH, since we didn’t specify a different one.

Here’s the command we need in our case:

$ git clone ssh://user@ .

We are explicitly telling Git to use SSH (which it would do anyway). We are also specifying a connection port with :2222, followed by the path/to/repo.

Obviously, 2222 is never a good port to use because it’s easy to guess. I’m just demonstrating the functionality here.

All done. Go version-control something.

Leave a Reply

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