I have recently come across a situation requiring me to clone a repository using a private key of remote machine in a staging server. Basically when the public key is added to the list of authorized keys to the server, then while cloning it will search for the ppk that resides in ~/.ssh/id_rsa. But here we have to forcefully choose a private key for git clone and found the below given solution that solves the issue.
If you have a ppk file, please see to that if its openssh format. If not then we need to convert the same putty tools available for windows. But let me show how to do the same using linux commands. For this instance, Let me assume, the filename is read as private_key.ppk and inorder to convert to openssh format, Please run the following command on terminal.
In order to use puttygen, you will need to have putty-tools installed in your system. If not installed, please run the following command before running the conversion command
sudo apt-get install putty-tools (ubuntu) [check similar command for debian/fedora]
Now you have openssh compatiable ppk key named as “private_key”, place it anywhere of your choice and I prefer it to reside in .ssh folder. Since we have our ppk ready, it should be mentioned that for any repo to use this ppk as identity to map with public keys listed in the authorized keys list. Create a file called config inside “~/.ssh/” folder and add the following lines of code. (Considering git url as email@example.com@sathees:testrepo.git)
Host gittest HostName github.com User git IdentityFile /home/satheskumar/.ssh/private_key **Note : we need to make sure the permission of the private key should be “700”
Now its ready to debug whether it works or not. Type
ssh -v git@gitest
It will give us the debug information and should be successful :). And we should be good enough to clone the repo as ..
git clone git@gittest@sathees:testrepo.git