git 保存 ssh 密钥失败

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

Saving ssh key fails

gitgithubssh-keys

提问by Eva Dias

i just started a Git tutorial and I get to a deadend: I try to generate a rsa key part and it fails. I did this, in git bash:

我刚刚开始了一个 Git 教程,但我走到了死胡同:我尝试生成一个 rsa 密钥部分,但它失败了。我这样做了,在 git bash 中:

ssh-keygen -t rsa -C "[email protected]"

And i got this:

我得到了这个:

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Eva/.ssh/id_rsa):
enter passphrase:
enter same passphrase again:
open /c/Users/Eva/.ssh/id_rsa failed: no such file or directory.
Saving the key failed:/c/Users/Eva/.ssh/id_rsa.

I tried to save in a different folder and it went OK. but now i do the command ssh -T [email protected]and it gives me the error permisson denied (publickey).

我尝试保存在不同的文件夹中,结果正常。但现在我执行命令ssh -T [email protected],它给了我错误permisson denied (publickey).

采纳答案by First Zero

If you prefer to use a GUI to create the keys

如果您更喜欢使用 GUI 来创建密钥

  1. Use Putty Gen to generate a key
  2. Export the key as an open SSH key
  3. As mentioned by @VonC create the .ssh directory and then you can drop the private and public keys in there
  4. Or use a GUI program (like Tortoise Git) to use the SSH keys
  1. 使用 Putty Gen 生成密钥
  2. 将密钥导出为开放的 SSH 密钥
  3. 正如@VonC 所提到的,创建 .ssh 目录,然后您可以将私钥和公钥放在那里
  4. 或者使用 GUI 程序(如Tortoise Git)来使用 SSH 密钥

For a walkthrough on putty gen for the above steps, please see http://ask-leo.com/how_do_i_create_and_use_public_keys_with_ssh.html

有关上述步骤的腻子生成演练,请参阅http://ask-leo.com/how_do_i_create_and_use_public_keys_with_ssh.html

回答by csaba.sulyok

If you're using Windows, the unix-style default path of ssh-keygen is at fault.

如果您使用的是 Windows,则 ssh-keygen 的 unix 样式默认路径有问题。

In Line 2 it says Enter file in which to save the key (/c/Users/Eva/.ssh/id_rsa):. That full filename in the parantheses is the default, obviously Windows cannot access a file like that. If you type the Windows equivalent (c:\Users\Eva\.ssh\id_rsa), it should work.

在第 2 行,它说Enter file in which to save the key (/c/Users/Eva/.ssh/id_rsa):。括号中的完整文件名是默认值,显然 Windows 无法访问这样的文件。如果您键入 Windows 等效项 ( c:\Users\Eva\.ssh\id_rsa),它应该可以工作。

Before running this, you also need to create the folder. You can do this by running mkdir c:\Users\Eva\.ssh, or by created the folder ".ssh." from File Explorer (note the second dot at the end, which will get removed automatically, and is required to create a folder that has a dot at the beginning).

在运行之前,您还需要创建文件夹。您可以通过运行mkdir c:\Users\Eva\.ssh或创建文件夹“.ssh”来执行此操作。来自文件资源管理器(注意末尾的第二个点,它将被自动删除,并且需要创建一个开头有一个点的文件夹)。

c:\Users\Administrator\.ssh>ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/Administrator/.ssh/id_rsa): C:\Users\Administrator\.ssh\id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\Administrator\.ssh\id_rsa.
Your public key has been saved in C:\Users\Administrator\.ssh\id_rsa.pub.
The key fingerprint is:
... [email protected]
The key's randomart image is:...`

I know this is an old thread, but I thought the answer might help others.

我知道这是一个旧线程,但我认为答案可能对其他人有所帮助。

回答by VonC

It looks like you are executing that command from a DOS session (see this thread), and that means you need to create the .sshdirectory before said command.

看起来您正在从 DOS 会话执行该命令(请参阅此线程),这意味着您需要.ssh在该命令之前创建目录。

Or you can execute it from the bash session (part of the msysgit distribution), and it should work.

或者您可以从 bash 会话(msysgit 发行版的一部分)执行它,它应该可以工作。

回答by Jared

I had the same issue. I had to provide the full path using Windows conventions. At this step:

我遇到过同样的问题。我必须使用 Windows 约定提供完整路径。在这一步:

Enter file in which to save the key (/c/Users/Eva/.ssh/id_rsa):

Enter file in which to save the key (/c/Users/Eva/.ssh/id_rsa):

Provide the following value:

提供以下值:

c:\users\eva\.ssh\id_rsa

c:\users\eva\.ssh\id_rsa

回答by whenov

You have to create the .ssh folder yourself for saving ssh keys.

您必须自己创建 .ssh 文件夹以保存 ssh 密钥。

By the way, I used this path style: C:/Users/you/.ssh/id_rsa

顺便说一句,我使用了这种路径样式: C:/Users/you/.ssh/id_rsa

回答by Tanya Gupta

I struggled with the same problem for a while just now (using Mac). Here is what I did and it finally worked:
(1) Confirm the .ssh directory exists:

我刚才在同样的问题上挣扎了一段时间(使用 Mac)。这是我所做的,它终于奏效了:
(1)确认 .ssh 目录存在:

#show all files including hidden
ls -a 

(2) Accept all default values by justpressing enter at the prompt

(2)接受所有默认值,只是按在提示符下输入

Enter file in which to save the key (/Users/username/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

You should get a message :

您应该收到一条消息:

Your identification has been saved in /Users/username/.ssh/id_rsa.
Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
The key fingerprint is:
BZA156:HVhsjsdhfdkjfdfhdX+BundfOytLezXvbx831/s [email protected]
The key's randomart image is:XXXXX

PS If you are configuring git for rails, do the following (source):

PS 如果您正在为 rails 配置 git,请执行以下操作(源代码):

git config --global color.ui true
git config --global user.name "yourusername"
git config --global user.email "[email protected]"
ssh-keygen -t rsa -C "[email protected]" 

(then accept all defaults by pressing enter)

(然后按回车接受所有默认值)

回答by Mario Neubauer

In Windows I had to create the environment variable HOMEpointing to my user profile first (C:\Users\<name>)or whatever directory you prefer.

在 Windows 中,我必须首先创建HOME指向我的用户配置文件(C:\Users\<name>)或您喜欢的任何目录的环境变量。

Then start a new command line window, create a a .sshdirectory in your user profile or choosen diretory using mkdir ".ssh"command.

然后启动一个新的命令行窗口,.ssh在您的用户配置文件中创建一个目录或使用mkdir ".ssh"命令选择目录。

After doing that I was able to use the ssh-keygen without any path problems.

这样做之后,我能够使用 ssh-keygen 而没有任何路径问题。

回答by Finger Picking Good

Your method should work fine on a Mac, but on Windows, two additional steps are necessary.

您的方法在 Mac 上应该可以正常工作,但在 Windows 上,还需要两个额外的步骤。

  1. Create a new folder in the desired location and name it ".ssh." (note the closing dot - this will vanish, but is required to create a folder beginning with ".")
  2. When prompted, use the file path format C:/Users/NAME/.ssh/id_rsa (note no closing dot on .ssh).
  1. 在所需位置创建一个新文件夹并将其命名为“.ssh”。(注意结束点 - 这将消失,但需要创建一个以“.”开头的文件夹)
  2. 出现提示时,使用文件路径格式 C:/Users/NAME/.ssh/id_rsa(注意 .ssh 上没有结束点)。

Saving the id_rsa key in this location should solve the permission error.

将 id_rsa 密钥保存在此位置应该可以解决权限错误。

回答by Richardd

I faced the same problem. Solution on windows:

我遇到了同样的问题。窗户上的解决方案:

  1. open start menu and type cmd
  2. Right and choose run as administrator
  3. Then type cd Users_YOURUSERNAME_\ Replace "YOURUSERNAME" with your windows account name
  4. The type: mkdir .ssh
  1. 打开开始菜单并输入cmd
  2. 右键选择以管理员身份运行
  3. 然后输入 cd Users_YOURUSERNAME_\用您的 Windows 帐户名替换“ YOURUSERNAME
  4. 方式: mkdir .ssh

This will create a .ssh folder.

这将创建一个 .ssh 文件夹。

回答by P Mill

For MacOS

对于 MacOS

Open terminal and make sure you have .ssh directory.

打开终端并确保您有 .ssh 目录。

On your home(~) folder enter ls -haland you will see all hidden directories and make sure you have .ssh directory, if not do mkdir .ssh

在您的 home(~) 文件夹中输入ls -hal,您将看到所有隐藏目录并确保您有 .ssh 目录,如果没有mkdir .ssh

then enter this ssh-keygen -t rsa -C "[email protected]"

然后输入这个 ssh-keygen -t rsa -C "[email protected]"

then you have: Generating public/private rsa key pair. Enter file in which to save the key (/Users/YOURUSERNAME/.ssh/id_rsa):

那么你有: Generating public/private rsa key pair. Enter file in which to save the key (/Users/YOURUSERNAME/.ssh/id_rsa):

press Enter (you don't need to enter nothing if you agree with that path or you need to enter your path from root of volume)

按 Enter(如果您同意该路径,则不需要输入任何内容,或者您​​需要从卷的根目录输入路径)

then follow answer what is gonna ask press Enter.

然后按照回答要问的问题按 Enter。

Check it here https://help.github.com/en/enterprise/2.16/user/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

在这里检查https://help.github.com/en/enterprise/2.16/user/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent