CentOS 6, Git 1.7
This is a further addition to the article Secure SSH on CentOS 6 And RHEL.
By default, Git will try to connect to a remote host over port 22 (the default SSH port). As a security measure, and as a part of securing your server, we need to be able use Git on an alternate port, view the article for details.
There are a few options available to you, but the only one that works reliably for me is the following method. You should use whatever you are comfortable with. On the local machine, we can tell Git to connect to the remote host on a different port by specifying the port number in our git add declaration.
$ git remote add myserver ssh://18.104.22.168:443/path/to/repo.git
Alternatively, you can directly edit the Git config file.
$ vi .git/config
And then specify the port number and the ssh:// connection method.
# a default git remote entry:
url = firstname.lastname@example.org:/path/to/repo.git
# using a custom port (other than 22):
url = ssh://email@example.com:443/path/to/repo.git
And that’s it. You don’t need to reload anything, it should work straight away. Just use your regular git pull and git push commands.
As I said, there are other methods to get this done. For example, you could just add the following to a ~/.ssh/config file:
I prefer NOT to use the ~/.ssh/config method because I found it to be unreliable in the long run.
Your choice tho 🙂