1

I installed Git for Windows and Powershell 7.1. When I try to clone a repository from git bash using ssh key, it works perfectly. However when I try to do similar from Powershell 7.1, I get a fatal: Could not read from remote repository error.

Steps Followed

1. PS> Start-Service ssh-agent
2. PS> ssh-add D:\Keys\.ssh\my_private_key (I get identity added message)
3. PS> git clone git@github.com:my-username/my-repo.git

Error Message

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
Indrajit
  • 2,152
  • 1
  • 14
  • 20

1 Answers1

2

That means ssh, in that Powershell session, is trying to look for SSH keys at %USERPROFILE% instead of D:\Keys

Check in your git bash if you have a ~/.ssh/config file which would specify the right private key to use for Host github.com.
And check what ~ (that is echo $HOME) resolves in said git bash session.
If should not be the same as the default HOME in a Powershell session, where git defaults to %USERPROFILE%

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks - copying my id_rsa file to C:\Users\username\.ssh\ did the trick! – Indrajit Jan 06 '21 at 04:32
  • Now the question is, is there a way to make Powershell use the key file kept somewhere, instead of using the one in %USERPROFILE%? – Indrajit Jan 06 '21 at 05:46
  • Yes, you can use a similar config file to specify the private key path. Put the config file in the same folder you just used. – VonC Jan 06 '21 at 08:18