使用 Git 生成 SSH 密钥时出错:“没有这样的文件”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6237955/
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-19 05:32:47  来源:igfitidea点击:

Error when generating an SSH key with Git: "no such file"

git

提问by Konrad

I continually run into the same error when I try to generate an SSH key:

当我尝试生成 SSH 密钥时,我不断遇到相同的错误:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/konrad/.ssh/id_rsa):

Here I press enter.

在这里我按回车键。

Could not create directory '/home/konrad/.ssh'

Then I enter my passphrases.

然后我输入我的密码。

open /home/konrad/.ssh/id_rsa failed: No such file or directory.
Saving the key failed: /home/konrad/.ssh/id_rsa.

I've tried re-installing Git multiple times, but that hasn't helped. I think it may be because C:/Users/Konrad should be the default directory, rather than /home. Any advice?

我已经多次尝试重新安装 Git,但这并没有帮助。我认为可能是因为 C:/Users/Konrad 应该是默认目录,而不是 /home。有什么建议吗?

采纳答案by VonC

On msysgit, you need first to set the user environment variable HOME(which isn't set by default in Windows).

在 msysgit 上,您首先需要设置用户环境变量HOME(在 Windows 中默认情况下未设置)。

HOMEcan be set to any directory you want, you only have to make sure you have the right to write in it (and that the directory exists and a .sshunder it exists too).

HOME可以设置为任何你想要的目录,你只需要确保你有权在其中写入(并且该目录存在并且其.ssh下也存在)。

回答by Sean

Drop to a command line and type:

拖放到命令行并键入:

ssh-keygen -t rsa

And follow the prompts there. I'm pretty sure git's doing exactly that under the hood for you.

并按照那里的提示进行操作。我很确定git在幕后为你做这件事。