Git remote add SSH
In this day and age, the most widely used version control system is Git, which is operated by most developers within a team structure. This is mainly used to increase code efficiency, no matter how big or critical the project is.
In this section, we will learn how to add SSH keys to Git.
Secure Shell (SSH) keys
SSH is the abbreviation of Secure Shell. It is a key generated to introduce a secure alternative to the insecure remote communication of network protocols.
SSH keys are used to provide its users, especially system administrators, with a platform to transfer remote files, can be used to manage networks, and can also be used to remotely access operating systems.
In this short guide, we will see how to add an additional SSH port git remote
. SSH server works on port 22 by default.
If we run it on any different port, we will face an error, ie error ssh: connect to host 192.158.xx.xx port 22: Connection refused
. So, we can also change the ports available in our system.
git remote add
When we start a local repository, it is necessary to add a remote repository where we can efficiently push our code. This can be done with the Git command git remote add .
The command git remote add
is used to establish association records for a new remote repository. By default, this command requires the local server username and IP address to add a new remote repository, as shown below:
git remote add remote_name ssh://username@ip_address/path-to-git-repo/repo.git
Example:
git remote add origin ssh://root@156.168.28.xxx/var/repositories/lau.git
A new remote was added through the above command named origin. If we change the SSH port, our code will not be pushed to the remote and we will face an error like this:
ssh: connect to host 156.168.28.xxx port 22: Connection refused
fatal: Could not read from remote repository.
Make sure you have the rights
and the repository exists.
This means that when adding git remote
, an attempt was made to connect to the default SSH port 22. Since we encountered an error, port 22 was modified.
Now we will set a different port when adding the remote.
Add another SSH port Git Remote
Here, we will specify another SSH port to add a new remote.
git remote add origin ssh://username@ip_address:port/path-to-git-repo/repo.git
Example:
git remote add origin ssh://root@156.168.28.xxx:5254/var/repository/lau.git
Now we can see that the above command will push our code to the new remote on a different SSH port specified (i.e. 5254).
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Changing drives in Git Bash
Publish Date:2025/03/30 Views:56 Category:Git
-
This short article will discuss how we can use Git Bash to have a Unix-style command line environment in Windows operating system and run multiple commands in this terminal. Git Bash Git is a collection of command-line utilities created to
Adding a remote branch in Git
Publish Date:2025/03/30 Views:142 Category:Git
-
Git does not allow its developers to create new branches on remote repositories. But instead, we can push an already existing local branch, and after doing so, we can bring it to the remote repository using some Git commands. In every versi
Synchronize your local repository with a remote repository in Git
Publish Date:2025/03/30 Views:92 Category:Git
-
This article outlines the process of syncing your local repository with a remote repository. We will also see how to sync a GitHub branch with a remote repository on the command line. Synchronize your local repository with a remote reposito
Creating a remote repository from a local repository in Git
Publish Date:2025/03/30 Views:105 Category:Git
-
This article discusses the necessary steps to create a remote repository based on a local repository. This is ideal when you have a local repository that needs to be available on a remote or SSH-enabled server. Creating a remote repository
Removing the upstream repository in Git
Publish Date:2025/03/30 Views:177 Category:Git
-
This article will teach you how to delete an upstream repository in Git. We may sometimes need to delete or change the remote repository that we use with our local repository. To do this, we can use the Git command git remote . Removing the
Creating and using branches in Git
Publish Date:2025/03/30 Views:99 Category:Git
-
This article introduces Git branches. We will see how Git branches can help you organize your projects. Some of the commands we will deal with are git branch and git checkout . git branch Use commands to create, display, and delete branches
Git force pull
Publish Date:2025/03/29 Views:166 Category:Git
-
In this tutorial, we will learn how to force pull changes from a remote repository in Git. Sometimes, we may need to discard local modifications and replace them with updates from a remote repository in a collaborative development environme
Git pulls Master into the branch
Publish Date:2025/03/29 Views:193 Category:Git
-
When developing software using the Git tool, you can create different branches for different features. When you make changes to master, these changes are not automatically added to other branches. This article will explain how to pull all t
Installing Git in Cygwin
Publish Date:2025/03/29 Views:116 Category:Git
-
Git is considered an active, innovative and highly recommended distributed version control system with a fantastic standalone command line while providing us with advanced features and complete internal methods. What is Cygwin Cygwin is con