2

I am using Sourcetree, and a repository configured via SSH and all operations work without a problem, but via Git Bash I am not able to perform a single fetch or pull:

git fetch
output: Permission denied (publickey).
fatal: Could not read from remote repository.

Is there a way to make Git to use this working Sourcetree configuration?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
artsch
  • 225
  • 2
  • 10

3 Answers3

3

I assume you are using Windows. You can use Git with either OpenSSH or Plink (PuTTY). When you use plink within Sourcetree, your SSH keys are read from PuTTY (e.g. pagent) or from what you configured withing Sourcetree, when you use Git Bash with OpenSSH on the other side they are read from ~/.ssh/id_whatever.

To fix it, use the same SSH technology in both clients. To change it in Sourcetree, go to preferences, and to change it in Git Bash, I think you need to re-install it. During the installation you are asked whether to use plink or OpenSSH.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hendrik M Halkow
  • 2,208
  • 15
  • 24
  • That is not exactly the solution but it helped me to understand the problem. This is the exact solution for this: https://stackoverflow.com/questions/35110079/git-bash-pageant-not-using-keys – artsch Feb 13 '18 at 15:09
1

I finally found the solution:

Git Bash and Pageant are not using keys

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
artsch
  • 225
  • 2
  • 10
0

Generate an SSH key pair on your machine:

ssh-keygen -t rsa -C "your.email@example.com" -b 4096

Copy the public key to the repository:

cat ~/.ssh/id_rsa.pub

Running cat will display the public key. You can also use SCP or something else to copy the public key over.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tim R
  • 514
  • 1
  • 8
  • 24