You can do git config --edit to bring up an editor with your settings in it to allow you to change them.
git clone ssh://[email protected]:[port]/gitolite-admin
Note that the port number should be there without the square brackets: []
Above answers are nice and great, but not clear for new git users like me. So after some investigation, i offer this new answer.
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.com
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
It's cool, the only thing we should know is that there two syntaxes for ssh url in git
ssh://[user@]host.xz[:port]/path/to/repo.git/
[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
When you want a relative path from your home directory (on any UNIX) you use this strange syntax:
ssh://[user@]host.xz[:port]/~[user]/path/to/repo
For Example, if the repo is in /home/jack/projects/jillweb
on the server jill.com
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
(Update: a few years later Google and Qwant "airlines" still send me here when searching for "git non-default ssh port") A probably better way in newer git versions is to use the GIT_SSH_COMMAND ENV.VAR like:
GIT_SSH_COMMAND="ssh -oPort=1234 -i ~/.ssh/myPrivate_rsa.key" \
git clone myuser@myGitRemoteServer:/my/remote/git_repo/path
This has the added advantage of allowing any other ssh suitable option (port, priv.key, IPv6, PKCS#11 device, ...).
Github has since posted a helpful article explaining how to solve this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With