Windows 7 上的 ssh 问题(gitbash 与 Windows cmd)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8496891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:39:06  来源:igfitidea点击:

ssh issue on windows 7 (gitbash vs. windows cmd)

windowsgitsshcmd

提问by Asad Iqbal

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.

我可以通过 GitBash 使用 ssh(即,对于带有 heroku 或 github 等的“git”),但我无法在同一台机器上从 Windows cmd 提示符执行相同操作。可能是什么问题?如果我没记错的话,它曾经在 cmd 提示符下工作。

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':

我得到了两个日志:这里是来自 cmd 的最后四行,与“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:

在 Git bash 的情况下:相应的行是:

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:

正如@snemarch 所暗示的,设置以下 env var 解决了我的问题:

set HOME=C:\Users\user1

回答by manojlds

Since you are using GitHub, from cmd try

由于您使用的是 GitHub,因此从 cmd 尝试

ssh -v -T [email protected]

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

查看它显示的键。也许也尝试使用 Git Bash 并比较输出。

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

这可能是因为 %HOME% 设置不正确。将其设置为包含您的.ssh目录(以及密钥)的目录

回答by snemarch

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 .

查看文件路径 - 在 cmd.exe 的情况下,“/.ssh/identity”可能不是您获得 SSH 密钥的地方:)。当您使用 git-bash 时,可能会进行 homedir 扩展,而不是本机 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.

不使用 cygwin ssh 和常规的 ssh 密钥文件,考虑使用 PuTTY 的 plink 进行 SSH 程序和选美的 ssh-agent。

回答by SGB

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

我会仔细检查您的系统路径是否包含对您的 git/bin 位置的引用