When you run git or ssh commands, it will first look ssh key from ~/.ssh folder. This is default folder ssh get keys from.
While working with multiple git clients, you might need to use different SSH keys for different clients.
In this article, we will discuss how to use specific SSH key. There are ways you can do it. We will discuss on them one by one.
SSH config file
By default, SSH will search for ~/.ssh/config file. So we will create file using nano command.
In this file, we will create alias for specific client.
Make sure you have enough permission for the file. Else you can change file permission with chmod command.
sudo chmod -R 600 ~/.ssh/github/id_rsa
Now you can use git commands like:
git clone [email protected]:jiteshmeniya/TCPDF-Laravel-Digital-Signature-Certificate.git
Using environment variable GIT_SSH_COMMAND
The second option is to use
GIT_SSH_COMMAND environment variable. This will use specific ssh key instead of default key.
ssh-agent bash -c 'ssh-add ~/.ssh/github/id_rsa; git clone [email protected]:jiteshmeniya/TCPDF-Laravel-Digital-Signature-Certificate.git'
Copyright 2022 HackTheStuff