5

I am able to use ssh (i.e., for 'git' with heroku or github etc.) through GitBash, but I cannot do the same from Windows cmd prompt on the same machine. What can be the problem? If I recall correctly, it used to work from cmd prompt.

The error I'm getting is:

Permission denied (publickey). fatal: The remote end hung up unexpectedly

I got both logs: here is last four lines from cmd which are different from 'git bash':

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).

in case of Git bash: the respective lines are:

debug1: Trying private key: /c/Users/user1/.ssh/identity
debug1: Offering public key: /c/Users/user1/.ssh/id_rsa
debug1: Remote: Forced command: gerve user1
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.

Resolved

As hinted by @snemarch, setting following env var solved my problem:

set HOME=C:\Users\user1
3
  • What is the error you are getting. You can't just say "I cannot do the same". Give some detail Commented Dec 13, 2011 at 22:14
  • Sorry, here is the error. __ Permission denied (publickey). fatal: The remote end hung up unexpectedly. ---- Commented Dec 14, 2011 at 23:12
  • How did you generate the logs? Commented Jan 21, 2022 at 17:23

3 Answers 3

8

Since you are using GitHub, from cmd try

ssh -v -T [email protected]

See the keys that it is presenting. Maybe try from Git Bash also and compare the output.

This could be because %HOME% is not correctly set. Set it to the directory that contains your .ssh directory ( and hence the keys)

Sign up to request clarification or add additional context in comments.

4 Comments

I added the logs into my question. I am not sure how to fix it.
It didn't exactly solve my problem, but it gave me a direction. I just updated my question with the resolution.
@AsadIqbal - As per the resolution, my answer exactly solves it. Didn't I say that %HOME% might not be set?
yeah. When I read your comment for the first time, i felt that you meant %HOMEPATH% which was properly set in my env: HOMEDRIVE=C: HOMEPATH=\Users\niqbal HOME=C:\Users\niqbal
1

Look at the file paths - "/.ssh/identity", in the case of cmd.exe, is probably not where you've got your SSH keys :). Probably a case of homedir expansion being done when you're on the git-bash, but not on native cmd.exe .

Instead of using cygwin ssh and the regular ssh key files, consider using PuTTY's plink for SSH program and pageant for ssh-agent.

Comments

0

I'd double check your system path includes a reference to your git/bin location

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.