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?
You can replace the two commands with this one command: git clone -c "core. sshCommand=ssh -i ~/. ssh/<your_key>" [email protected]:<user>/<repo>. git .
To specify a private key file in SSH from the command line, you can simply use -i option in the ssh command. However, things get complicated when you have multiple private keys. In that case, you can declare which private key to use for each SSH server, in your SSH configuration file which is found at ~/. ssh/config .
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
One option is to use ssh-agent
and provide a file name to ssh-add
.
For example:
$ ssh-agent /bin/bash
$ ssh-add ~/mykeys/id_rsa
I would have said put the file name in ~/.ssh/config
, but you likely would not have access to this file, too.
You can give ssh
the private key to use with the -i keyfile
option.
Now how to say git which options to pass to ssh?
The GitTips page says create a wrapper script and point to it with the GIT_SSH
environment variable.
It looks like you also can use the git configuration core.gitProxy
, but I did not find a good example and some mailing list message suggests it is only for the git:
protocol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With