Git - SSH Protocol



The SSH (Secure Shell) protocol is a widely used transport protocol that is simple to set up and widely available for self-hosted Git repositories. The operations such as cloning, pushing, and fetching are all supported. Here Git uses SSH for authentication of the users and encryption of data transferred over network.

  • It is frequently selected because SSH access to servers is either pre-established or simple to set up.

  • Git operations are made easier to use and more reliable by SSH's provision of authorized network connection.

Key Features

Some of the key features of SSH are:

1. Authentication Secured − Public key cryptography is used by SSH for authentication. A pair of SSH keys is generated by the user:

  • Public Key − Key that is shared with the Git server, such as GitHub, GitLab.

  • Private Key − Key that remains on the user's machine and does not require a password to access.

2. Data Encryption − Confidentiality and protection maintained by encryption of all the data that gets transferred from client to server and vice-versa.

3. Easy Access − Automatic authentication takes place, once the SSH key is configured. Hence there is no need to enter password every time you connect to the remote repository.

How It Works?

Following are the steps that describes how SSH protocol works:

  • Generating SSH Keys − Generate the SSH key pair on your local machine, using ssh-keygen.

  • Adding Public Key to Server − The public key generated in the previous step is added to the remote Git server, ie., to your GitHub or GitLab account under the SSH keys.

  • Using SSH URLs − Use the SSH URL to access the repository, instead of using HTTP(S) URL.

  • SSH-Agent − In order to cache your SSH key, to avoid adding the key's paraphrase repeatedly, you can use the ssh-agent on your local machine.

To clone a Git repository over SSH, use either:

git clone ssh://[user@]server/project.git

or

git clone [user@]server:project.git

If no username is specified in the URL, Git assumes the current logged-in user for authentication.

Advantages

Following are few of the advantages of using SSH for Git repositories:

  • Highly Secured − SSH improves overall security by ensuring secure access through verified and encrypted data transfers.

  • Fater Performance −SSH is effective in improving data transfer size and performance, compared to HTTPS and Local protocols.

  • Trusted Connectivity − The connection and communication with server is trusted and secured, after the initial connection, where the server's SSH fingerprint is verified.

  • Passwordless Access − After the initial setup, there is no need to enter the password to interact with the remote repository.

Disadvantages

Following are some of the disadvantages of using SSH for Git repositories:

  • Complex Setup − Setting up SSH keys can be complex and time-consuming, especially for beginners.

  • Lack of Support − The lack of support for anonymous access in SSH for Git repositories is a disadvantage.

  • Limitation with Open-Source − Clones and repository access require SSH access, which can be limiting for open-source projects that frequently permit anonymous cloning.

  • Performance Overhead − SSH is generally fast, but the encryption and decryption process introduces latency during data transmission.

  • Difficult in Collaborative Environment − It is less ideal for environments where multiple users need to access a shared account, will require individual SSH key added to the account.

In spite of these limitations, SSH remains the most trusted and widely used secured communication protocol.

Advertisements