2

I'm using bitbucket and on my laptop I cannot use git to clone the repository. I'm getting an error:

Permission denied(publickey).

How can I fix this? I don't remember setting a public key but if I did apparently it doesn't work. (I'm using windows.)

alternative
  • 12,703
  • 5
  • 41
  • 41
Greyshack
  • 1,901
  • 7
  • 29
  • 48
  • removed stuff about bash as its irrelevant to the question (its just something that confused you because using git on windows is weird) – alternative Jun 27 '15 at 22:12

2 Answers2

1

It just means Git doesn't find the public/private key in %HOME%/.ssh.
Which in turn means the shhd (ssh daemon on the server) doesn't find a matching public key in the server ~git/.ssh/authorized_keys.

You can make sure to use an https url for instance (which is what the OP is intended to use):

cd c:\path\to\my\repo
git remote set-url origin https://bitbucket.org/<owner>/<repo>

Regarding known_hosts, a simple ssh -T git@bitbucket.org will fix that:

$ ssh -T git@bitbucket.org
The authenticity of host 'bitbucket.org (131.103.20.168)' can't be established.
RSA key fingerprint is 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40.
Are you sure you want to continue connecting (yes/no)?

Add 'yes' and bitbucket.org would be added to the ~/.ssh/known_hosts.
Yet, in the absence of a registered public key, the result would still be the same.

Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bitbucket.org,131.103.20.168' (RSA) to the list of known hosts.
Permission denied (publickey).

The bash on Git for Windows is not weird:

  • the git bash in msysgit/Git for windows 1.9.5 is an old one:

    GNU bash, version 3.1.20(4)-release (i686-pc-msys)
    Copyright (C) 2005 Free Software Foundation, Inc
    

But with the phasing out of msysgit (Q4 2015) and the new Git For Windows (Q2 2015), you now have Git for Windows 2.4.4.
It has a much more recent bash, based on the 64bits msys2 project, an independent rewrite of MSYS, based on modern Cygwin (POSIX compatibility layer) and MinGW-w64 with the aim of better interoperability with native Windows software. msys2 comes with its own installer too.

  • The git bash is now (with the new Git For Windows):

    GNU bash, version 4.3.33(3)-release (x86_64-pc-msys)
    Copyright (C) 2013 Free Software Foundation, Inc.
    
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm sorry but I dont really understand git that much. I don't have the repo on the computer yet. I want to clone it and that's when the problem occurs. And I'm using the link from the site with https – Greyshack Jun 27 '15 at 18:55
  • @Greyshack What command are you typing? And what Git version are you using? (git --version) – VonC Jun 27 '15 at 19:01
  • 1.9.5.msysgit.0 Strangely it worked this time, I was probably doing something wrong. Anyways thanks for your help. – Greyshack Jun 27 '15 at 19:18
  • @Greyshack Great! You can also start trying more recent versions of "Git for Windows" now: Git 2.4.4 is a simple archive to unzip anywhere you want and to add to your PATH: https://github.com/git-for-windows/git/releases – VonC Jun 27 '15 at 19:20
  • Wrong. The error means it doesn't find your public key in the server's known hosts – alternative Jun 27 '15 at 22:11
  • @alternative I disagree. Even with a complete known_hosts, the absence of a registered public key would still triggered the same error. See my edited answer. – VonC Jun 28 '15 at 05:46
  • @VonC Urgh sorry, I meant authorized_keys – alternative Jun 28 '15 at 17:12
  • @alternative ok, but you would get the same "Permission denied (publickey)." if you don't have any key defined on the client side (authorized_keys is on the server side). I still fail to see how this answer is "wrong". – VonC Jun 28 '15 at 17:33
  • Because if the key isn't defined on the client side, authorized_keys doesn't have the public key either (since the key doesn't exist). – alternative Jun 28 '15 at 18:01
  • @alternative let's keep it client-side for the benefit of the OP. No need look at the server side for now: no ssh key on the client means ""Permission denied (publickey)." Again, nothing "wrong". – VonC Jun 28 '15 at 18:03
  • @VonC No, it doesn't. Run ssh-keygen and you still get the same error. – alternative Jun 28 '15 at 18:21
  • @alternative I agree and have edited the answer accordingly. – VonC Jun 28 '15 at 18:24
0

Bitbucket has SSH and HTTPS access.

Plus you will see that it also provides you with an URL (for https) when you click on the clone button on their website.

If you still have a problem, consult with your repo owner/admin.

Alp
  • 3,027
  • 1
  • 13
  • 28