How to Specify SSH key for Git repository

How to Specify SSH key for Git repository

How to Specify SSH key for Git repository

In this post we will give you information about How to Specify SSH key for Git repository. Hear we will give you detail about How to Specify SSH key for Git repository And how to use it also give you demo for it if it is necessary.

You may need to handle multiple SSH keys if you use SSH keys with Git to clone and pull your repositories. For instance, it’s typical to set up a “deploy key” in GitHub with read-only access. When you have numerous repositories, you must create distinct SSH deploy keys since GitHub requires you to utilize separate keys for each repository.

This example shows how to use different SSH keys for each remote repository.

How to Specify SSH key for Git repository

Step 1: Generate SSH keypair

There are numerous ways to create an SSH keypair. You can skip this step if you already have them.

# Generate public and private SSH keys

ssh-keygen
#or
ssh-keygen -f /home/{user}/.ssh/github-my-repo.id.rsa

If the config file is new, you might need to do chmod 600 ~/.ssh/config.

NOTE: On Linux and macOS, verify that the permissions on your IdentityFile are 400. SSH will reject, in a not clearly explicit manner, SSH keys that are too readable. It will just look like a credential rejection. The solution, in this case, is:

chmod 400 ~/.ssh/{privateKey}

Step 2: Configure SSH to use the IdentityFile

You must instruct the Git Client to utilize the private SSH key when attempting to perform git operations with the remote repository once you have produced your public and private SSH keys and the remote server has your public key configured.

Open the SSH config file using your favorite text editor (I prefer nano, but You can use VI or any other of your favorite.):

nano /home/{user}/.ssh/config

And include the custom host.

# Here you can give any name of a host.
Host my-personal-repo

    # The host that has the remote Git repository
    Hostname github.com

    # Username for remote SSH user (For GitHub, everyone uses the name 'git')
    User git

    # Path to your private SSH key
    IdentityFile /home/{user}/.ssh/{privateKey}

If you want to use this SSH host with Git, format your file like this:

git clone my-personal-repo:client-a/laravel-api.git

Or if you already have the local repository and you want to add a new remote:

git remote add origin my-personal-repo:client-a/laravel-api.git

Thank you for reading How to Specify SSH key for Git repository article. Hope this code and post will helped you for implement How to Specify SSH key for Git repository. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US