Git On Custom SSH Port

git clone ssh://[email protected]:[port]/gitolite-admin

Note that the port number should be there without the square brackets: []


When you want a relative path from your home directory (on any UNIX) you use this strange syntax:

ssh://[user@]host.example[:port]/~[user]/path/to/repo

For Example, if the repo is in /home/jack/projects/jillweb on the server jill.example and you are logging in as jack with sshd listening on port 4242:

ssh://[email protected]:4242/~/projects/jillweb

And when logging in as jill (presuming you have file permissions):

ssh://[email protected]:4242/~jack/projects/jillweb


Above answers are nice and great, but not clear for new Git users like me. So after some investigation, I offer this new answer.

What's the problem with the SSH config file way?

When the config file does not exists, you can create one. Besides port the config file can include other SSH config option:user IdentityFile and so on, the config file looks like

Host mydomain.example
    User git
    Port 12345

If you are running Linux, take care the config file must have strict permission: read/write for the user, and not accessible by others

What about the SSH URL way?

It's cool, the only thing we should know is that there two syntaxes for SSH URL in Git

  • standard syntax ssh://[user@]host.xz[:port]/path/to/repo.git/
  • scp like syntax [user@]host.xz:path/to/repo.git/

By default Gitlab and GitHub will show the scp like syntax URL, and we can not give the custom SSH port. So in order to change SSH port, we need use the standard syntax