Using Non-Standard SSH Port With Gitolite1 min read

If you are running a development network from home you more than likely are using some sort of version control. Git has become very popular in recent years and Gitolite along with Git is what I prefer.

The standard port for SSH is port 22. However, in a home network with multiple VMs it may become necessary to use a different external port. Through port forwarding, it becomes possible to access your home version control from the outside world.

First, choose the port you want to utilize for external access. In your router, set up a forwarding rule which forwards the desired port to the appropriate VM. In the VM you will also need to set up a forwarding rule. For CentOS, you need to use the firewall-cmd command. Once you set up port forwading in the firewall of the VM, you will need to create a .ssh config file on the machine(s) accessing the repositories on the non-standard port.

In your .ssh directory create a config file named config. Here you will place information for the host you wish to connect to. Essentially, you are creating an alias. The following is an example of an alias in a config file.

Host gitolite
 User git
 Port 1234

After creating the config file you can now access your home network repositories using the aliased host name. For example, if you previously used git@localhost:reponame it would have connected using port 22. Now you can use git@gitolite:reponame and it will connect using the aliased host name and port. If everything else was setup correctly port forwarding will get everything connected properly and you will have outside access to your home repositories.

Leave a Reply

Your email address will not be published.