- 25 hours to Bariloche, but the views are worth it. https://t.co/7W7cN2t1sm 22 hours ago
- RT @SaintGimp: GWB: "No democracy pretends to be a tyranny. Most tyrannies pretend to be democracies. Democracy remains definition of polit… 2 days ago
- Seattle, WA ✈️ Atlanta, GA ✈️ Buenos Aires, Argentina ✈️ San Carlos de Baroloche, Argentina #AdventureTime @nodeconfar we are on our way! 2 days ago
- RT @aaronpk: Super happy to announce that my book "OAuth 2.0 Simplified" is now available! oauth2simplified.com 3 days ago
- RT @GraceStarling4: For those carrying their #MeToo with them silently, you are loved, cherished, and believed. You do not owe your story t… 4 days ago
PowerShell, msysgit 1.7.9 and Permission denied (publickey) Errors
March 20, 2012Posted by on
TLDR: Add “$env:home = resolve-path ~” to your PowerShell profile.
I recently updated my work Virtual Machine to the latest release of msysgit 1.7.9 to resolve some issues I was having with global settings not being obeyed. After the installation I noticed that I was no longer able to update repositories from PowerShell. The output I was getting looked something like this:
GIT [dirkdiggler] on [master] (clean) | C:\projects\foo -> git pull Permission denied (publickey). fatal: The remote end hung up unexpectedly
This was unexpected and the first thing I thought of was the recent security issue with GitHub, and maybe my work key needed to be validated. I checked GitHub and everything seemed to be set up correctly. I even went so far as to generate new keys with no success.
Next up, it occurred to me to try connecting via git bash.
dirkdiggler@DIRKDIGGLER-VM /c/projects/foo (master) $ ssh firstname.lastname@example.org Hi dirkdiggler! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
Bash seems to be working fine. I then started troubleshooting my connection from PowerShell. I tried testing ssh first with the following command.
GIT [dirkdiggler] on [master] (clean) | C:\projects\foo -> ssh email@example.com Permission denied (publickey).
So it looks like the problem was not with git but with establishing an ssh connection to GitHub. I wanted to see exactly what was happening when trying to connect via ssh, so I ran the following command with enables verbose logging of the connection.
GIT [dirkdiggler] on [master] (clean) | C:\projects\foo -> <b>ssh -v firstname.lastname@example.org</b> OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007 debug1: Connecting to github.com [184.108.40.206] port 22. debug1: Connection established. debug1: identity file /.ssh/identity type -1 debug1: identity file /.ssh/id_rsa type -1 debug1: identity file /.ssh/id_dsa type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5github2 debug1: match: OpenSSH_5.1p1 Debian-5github2 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_4.6 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-cbc hmac-md5 none debug1: kex: client->server aes128-cbc hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Host 'github.com' is known and matches the RSA host key. debug1: Found key in /.ssh/known_hosts:1 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Trying private key: /.ssh/identity debug1: Trying private key: /.ssh/id_rsa debug1: Trying private key: /.ssh/id_dsa debug1: No more authentication methods to try. Permission denied (publickey).
This output did not give me any immediate ideas on the problem but I thought I might try the same command from git bash. I won’t include the full output here, but I did notice something different right away. Check out the following lines from the output. Compare them to lines 6-8 above.
debug1: identity file /c/Users/MGALFAPAIR/.ssh/identity type -1 debug1: identity file /c/Users/MGALFAPAIR/.ssh/id_rsa type 1 debug1: identity file /c/Users/MGALFAPAIR/.ssh/id_dsa type -1
So it looks like ssh running under PowerShell is looking for my public/private key pair in a different directory than under bash. Doing a quick google search I found that an environment variable named home is used when determining the path to look for keys. I went back to PowerShell and checked for the environment variable like so.
GIT [dirkdiggler] on [master] (clean) | C:\projects\foo -> Write-Host $env:home
No home variable set. So I set it like so.
GIT [dirkdiggler] on [master] (clean) | C:\projects\foo -> $env:home = Resolve-Path ~ GIT [dirkdiggler] on [master] (clean) | C:\projects\foo -> Write-Host $env:home C:\Users\MGALFAPAIR
Running the ssh test again, I am now able to connect. Adding the command to my PowerShell profile sets it automatically every time I start PowerShell resolving the problem completely.