user2351675
user2351675

Reputation: 13

How do I use the right key for SSH, connecting from Git Bash on Windows to remote server?

I'm trying to push my project on git to my remote Linux server from my local Windows PC.

I have no issues connecting to my server through SSH when I use PuTTY. But PuTTY is only for the remote server, and doesn't let me look in my own local pc - so I can't access my git repository to push from.

Instead I've been trying with Git Bash, where I go to the repository(master) of my git project, and then attempt "git push production master". Receiving "Permission denied (publickey)" in response in Git Bash.

I have loaded by private key from my user/.ssh folder on local pc, using PuTTYgen, copy/pasted the public key it shows into my Github account's SSH-keys. This is the same key that I use for connecting with PuTTY(which works).

If I use "git remote -v" in Git Bash, I receive what is the correct url for the server: " production ssh://[email protected]/var/repo/site.git (fetch) production ssh://[email protected]/var/repo/site.git (push) "

"notacop" is the admin user I made instead of root, which is also the one that I use in PuTTY.

If I attempt "ssh [email protected]" in Git Bash I also receive the "Permission denied (publickey)" response. So seemingly the issue is related to the publickey that Git Bash uses, as it can't connect at all.

My user/.ssh folder contains: digitalocean_private_key (is the one PuTTY uses/the one generated by PuTTYgen) + digitalocean_public_key

github_rsa + github_rsa.pub

id_rsa + id_rsa.pub

known_hosts


I feel like I've set things up in accordance with the general guidelines, and it does work in PuTTY, so the issue must be related to Git Bash and how Git Bash establishes ssh connection.

But I'm fairly clueless about how to fix the issue, and haven't been able to find a solution from searching. My guess is that it's something fairly simple, but I've been stuck on this for a couple weeks now, not getting anywhere because of it.

Any answers that can lead me in the right direction will be highly appreciated! If anything about my question is unclear, or you need more information to answer, please let me know.

Upvotes: 1

Views: 533

Answers (1)

janos
janos

Reputation: 124648

I don't know why Git Bash's own ssh doesn't seem to work for you, but I have a better recommendation: make Git Bash use PuTTY, by setting the GIT_SSH environment variable to the path of plink.exe (that's not a typo, it's not putty.exe, but another executable that comes with the zip of PuTTY tools).

The main advantage and reason to do this is so that Git Bash can benefit from pagent.exe, the key manager of PuTTY. So that you can enter your passphrase once, when adding your private key to Pagent, and then you don't need to re-enter it every time you perform remote operations in Git Bash.

Upvotes: 1

Related Questions