Karl Karl - 1 month ago 8x
Git Question

Can I specify private key in git config?

I want to use separate private key for a single git repository.

I don't have access to home directory or I can't set env variables as well.

Is there any I can specify it in


Because then I can chnage the .git/config to use ssh instead of https.
Currently I have hardcoded user:pass in url of config file


One option is to use authentication agent forwarding when logging into the remote machine to run git commands. Here's a guide to setting that up.

An authentication agent (usually ssh-agent) will store your keys in memory so you don't have to keep typing in the password. Authentication agent forwarding is when a remote machine is allowed to use your agent. When you ssh into a machine with forwarding, you can then ssh again from there as if you had all the keys of your local machine.

It's really handy and avoids the need to copy your private keys all over the place.