(git bash) push to bitbucket ignores SSH key
Asked Answered
F

5

11

I followed a bunch of blog trails around the web to find out how everything should be set up and I have the following situation:

First of all, ssh -T [email protected] returns the following result

conq: logged in as myuser.
You can use git or hg to connect to Bitbucket. Shell access is disabled.

That means I have the ssh key setup properly both local and in bitbucket, agreed?

I have a ~/.ssh/config with the following content:

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa

That key is there ofcourse.

However, when I try the command (taken from another tutorial) git push origin master, I will get a popup saying:

---------------------------
PuTTY Fatal Error
---------------------------
Disconnected: No supported authentication methods available (server sent: publickey)
---------------------------
OK   

Forcer answered 25/6, 2013 at 20:42 Comment(0)
F
20

Judging by the error PuTTY Fatal Error, it looks like Git is trying to use PuTTY to authenticate with ssh. The thing is PuTTY is not aware of your setting in ~/.ssh, at all. The setting in ~/.ssh is only meaningful when using openssh, shipped with Git Bash. It looks as if you have set the GIT_SSH environment variable to plink.exe, which is a tool that's part PuTTY.

You have two choices: you can either use PuTTY and plink.exe for ssh operations, or you can use the openssh that is part of Git Bash.

If you use PuTTY, then you need to manage your ssh keys with pageant.exe, which is also part of PuTTY. It's a pretty nice tool. Run it, and in the task tray you should see an icon. Right-click on that icon to add your private key. The other step to use PuTTY is setting GIT_SSH but it looks like you've already done that. In this setup git push will use plink.exe, which being part of PuTTY, will correctly find the private keys stored by pageant.ext.

If you want to use the openssh that is part of Git Bash, then all you need to do is get rid of the GIT_SSH setting. One way to make sure the setting is really empty when using git push is if you run the command like this:

GIT_SSH= git push origin master
Fikes answered 25/6, 2013 at 21:11 Comment(3)
Correct! This morning I woke up with an epiphany; remembering that the error actually came from putty, I reinstalled Git Bash this time configured with openssh instead of turtoise/putty plink etc. and it worked at once. The thing is, I had pageagent running and had the .ssh key imported there and still it wouldn't work. Took me all evening the day before... easy to lose track of time when dealing with ssh related things.Forcer
for those who are using PuTTY pageant with plink then the following command should be equivalent (assuming plink is in the PATH) plink -ssh [email protected]Amaranthine
When using GIT_SSH= git push origin master I get a fatal error. What am I missing here?Regimen
C
3

After all the other answers didnt do it for one of my collegues, I figured the following:

Since pushing to remotes like beanstalk works (https) and even ssh works using the git bash console, I figured it must have something to do with how SSH would be invoked, our remote was something like this:

user@server:/path/to/repo.git

So a simple which ssh gave us /bin/ssh

In the .bashrc profile we just added

export GIT_SSH=/bin/ssh.exe

and voila.

An easier solution would be to buy a mac! :)

Happy gitting

Coronary answered 15/4, 2015 at 9:55 Comment(2)
You sir - Are a genius! I have been struggling for hours and your one-liner fixed it in a sec. Tips fedoraBandaranaike
you are so right, thanks a lot for this answer. I struggled for hours with itRuffled
M
1

You are trying to connect to Bitbucket via SSH rather than through Git which is what the first error is telling you. That you are not allowed to connect to Bitbucket in that manner.

When you set up your repo, if you are off of a existing one in Bitbucket all you would have needed to do is:

git clone [email protected]:<UserName>/<Name of the Repo>.git

You would get a message about accepting a key and you would have been all set.

Now if you have an already existing repo, you can add the remote yourself but you would add that to .git/config

You would add [email protected]:<UserName>/<Name of the Repo>.git to the section [remote "origin"].

Magician answered 25/6, 2013 at 20:54 Comment(1)
Yeah, I had that already, but still it wouldn't use SSH. Turns out it was because I installed GIT to use TurtoisePlink and puttygen.exe, instead of the ssh client provided with Git Bash.Forcer
S
1

Try using cmd.exe. Git Bash seems to have issues with environment variables on my machine.

In CMD, echo %GIT_SSH% to see if it is set (PuTTY/Plink does that). If it is set, and you want to use openssh, clear it with set GIT_SSH=.

After doing that, I could push and pull using ssh in CMD with no issue, although Git Bash still does not work.

Sadducee answered 18/3, 2014 at 15:28 Comment(0)
W
0

For those facing this (or a similar problem), it was a completely different StackOverflow issue that hinted at my solution.

Turns out I had cloned from Bitbucket using the HTTPS address option instead of SSH.

enter image description here

And apparently if you run git while pointed at the HTTPS address, it doesn't give a toss if you've got a key or not.

  • Go to your .git/config
  • Check if your remote "origin" (or whatever) url is set to https://...
  • If so, go to your Bitbucket repo, hit the Clone button, switch from HTTPS to SSH, and copy the address starting git@bitbucket...
  • That's it.

(In your enthusiasm to test it out, don't forget to add your key to your agent again like I did.)

Wrest answered 3/4, 2022 at 16:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.