Linux Tutorials

Git Remote Add With Another SSH Port (Not 22)

Git Remote Add With Another SSH Port

In this brief article, you will learn to add a git remote with another SSH Port. By default, SSH server listens on port 22. If the SSH server runs on any other port, the command to add remote will fail with error ssh: connect to host 192.158.xx.xx port 22: Connection refuse.

What is Git?

Git is a free & open-source version control system that almost all developers use today. No matter what project you’re working on, Git can help you manage your code efficiently.

It is faster than any other way of transmitting code to a remote location. Its lightening fast performance can transmit the entire application within seconds to the production server, staging server or a bitbucket repository.

To learn more about git, read our Learn Git series.

Git remote add

After initializing the local repository, one needs to add at least one remote repository to push code to that remote. By default, git requires a server username and IP address to add a remote repository.

git remote add remote_name ssh://[email protected]_address/path-to-git-repo/repo.git

Example –

git remote add production ssh://[email protected]/var/repositories/lau.git

The above command will add a remote named production. If you changed the SSH port, the above remote will fail to push code and return the following error –

ssh: connect to host port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

It means git tried to connect to ssh on port 22. Since the port 22 has been modified, we need to specify another port when adding a remote.

Git Remote Add With Another SSH Port

git remote add production ssh://[email protected]_address:port/path-to-git-repo/repo.git

Example –

git remote add production ssh://[email protected]:3234/var/repository/lau.git
Git Remote Add With Another SSH Port
Git Remote Add With Another SSH Port

As you can see, the custom port needs to be specified while adding the remote. Now the above command will add a remote that will push code to repository on SSH port 3234.

LinuxAndUbuntu hosting is sponsored by massiveGRID

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This website uses cookies to improve your experience. We'll assume you're ok with this. Thank you! Ok Read More