Setting a custom path for git private SSH key on linux

ripper234 picture ripper234 · Mar 16, 2011 · Viewed 58.8k times · Source

I'm trying to setup a git client on linux. I uploaded my private key to the machine, and I understand that I should put it in ~/.ssh, but I don't have access to that folder.

How can I tell git to look for the private key somewhere else?

Answer

Felipe Sabino picture Felipe Sabino · Apr 28, 2011

You can achieve that using a ssh config file.

First create a file inside your ~/.ssh folder named config, you can use some command like the following

$ nano ~/.ssh/config

Then, the content of the file should have the location of your key based on each host name. for example:

Host github.com
 IdentityFile ~/myPublicKeyFolder/myGitHubFile
Host heroku.com
 IdentityFile ~/myPublicKeyFolder/myHerokuFile

So, when git tries to access each host it will follow the rules inside this config file based on the git host your trying to reach