保存 ssh 密钥失败

发布于 2024-12-05 06:28:16 字数 794 浏览 2 评论 0原文

我刚刚开始学习 Git 教程,却陷入了死胡同:我尝试生成 rsa 密钥部分,但失败了。 我在 git bash 中这样做了:

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

我得到了这个:

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.

我尝试保存在不同的文件夹中,结果一切顺利。但现在我执行命令 ssh -T [email protected] 它给了我错误权限被拒绝(publickey)。

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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

梦里梦着梦中梦 2024-12-12 06:28:16

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

第 2 行显示输入要保存密钥的文件 (/c/Users/Eva/.ssh/id_rsa):
括号中的完整文件名是默认的,显然 Windows 无法访问这样的文件。如果您输入 Windows 等效项 (c:\Users\Eva\.ssh\id_rsa),它应该可以工作。

在运行之前,您还需要创建该文件夹。您可以通过运行 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:...`

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

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

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.

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

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.

葬花如无物 2024-12-12 06:28:16

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

  1. 使用 Putty Gen 生成密钥
  2. 将密钥导出为开放的 SSH 密钥
  3. 正如 @VonC 所提到的,创建 .ssh 目录,然后您可以将私钥和公钥放入其中
  4. 或使用使用 SSH 密钥的 GUI 程序(例如 Tortoise Git

有关 putty gen 的演练以上步骤,请参阅 http://ask-leo.com/how_do_i_create_and_use_public_keys_with_ssh.html

If you prefer to use a GUI to create the keys

  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

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

青芜 2024-12-12 06:28:16

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

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

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

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

最美的太阳 2024-12-12 06:28:16

我有同样的问题。我必须使用 Windows 约定提供完整路径。
在此步骤:

输入要保存密钥的文件 (/c/Users/Eva/.ssh/id_rsa):

提供以下值:

c:\users\eva\.ssh \id_rsa

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

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

Provide the following value:

c:\users\eva\.ssh\id_rsa

橘味果▽酱 2024-12-12 06:28:16

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

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

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

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

桃气十足 2024-12-12 06:28:16

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

#show all files including hidden
ls -a 

(2) 只需在提示符下按 Enter 键即可接受所有默认值

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

您应该收到一条消息:

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 如果您正在为 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]" 

然后按 Enter 键接受所有默认值)

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:

#show all files including hidden
ls -a 

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

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

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)

—━☆沉默づ 2024-12-12 06:28:16

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

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

完成此操作后,我可以使用 ssh-keygen,而不会出现任何路径问题。

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

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

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

£烟消云散 2024-12-12 06:28:16

我在 Windows 上使用了 git 附带的 bash。问题是我假设我用来表示我的主路径的波形符 (~) 会正确扩展。使用 cd 时它确实有效,但要修复此错误,我必须给它绝对路径。

I was using bash on windows that came with git. The problem was I assumed the tilde (~) which I was using to denote my home path would expand properly. It does work when using cd, but to fix this error I had to just give it the absolute path.

半透明的墙 2024-12-12 06:28:16

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

  1. 在所需位置创建一个新文件夹并将其命名为“.ssh”。 (注意结束点 - 这将消失,但需要创建以“.”开头的文件夹)
  2. 出现提示时,使用文件路径格式 C:/Users/NAME/.ssh/id_rsa (注意 .ssh 上没有结束点) )。

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

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

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

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

寻找我们的幸福 2024-12-12 06:28:16

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

  1. 打开开始菜单并输入 cmd
  2. 右键并选择以管理员身份运行
  3. 然后输入 cd Users_YOURUSERNAME_\
    将“YOURUSERNAME”替换为您的 Windows 帐户名
  4. 类型:mkdir .ssh

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

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

This will create a .ssh folder.

看海 2024-12-12 06:28:16

对于 MacOS

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

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

然后输入此内容ssh-keygen -t rsa -C "[电子邮件受保护]"

那么您就拥有:正在生成公共/私有 rsa 密钥对。
输入要保存密钥的文件 (/Users/YOURUSERNAME/.ssh/id_rsa):

按 Enter(如果您同意该路径或需要从 root 输入路径,则无需输入任何内容音量)

然后按照回答要问的内容按 Enter 键。

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

For MacOS

Open terminal
and make sure you have .ssh directory.

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

then enter this 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):

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)

then follow answer what is gonna ask press 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

我的痛♀有谁懂 2024-12-12 06:28:16

对于 Windows,请使用 Enter 按钮 3 次 输入

要保存密钥的文件 (/c/Users/Rupesh/.ssh/id_rsa):
输入密码(没有密码则为空):
再次输入相同的密码:

它对我有用......

For windows use enter button 3 times

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

its work for me...

烟雨凡馨 2024-12-12 06:28:16

在 Mac 上,您首先必须 cd ~/.ssh 然后您可以执行 ssh-keygen

on Mac, you first have tocd ~/.ssh then you can do ssh-keygen

千里故人稀 2024-12-12 06:28:16

在使用 CMDER 的 Windows 8.1 上,我使用此文件路径 /c/Users/youruser/.ssh/id_rsa_whatever 创建了 ssh 密钥,问题是我正在使用的 : 。使用此路径,我在运行命令之前没有创建文件夹,因此无需运行 mkdir,因为命令会自动创建文件夹。

On Windows 8.1 using CMDER, I created the ssh key with this file path /c/Users/youruser/.ssh/id_rsa_whatever, the problem was the : that I was using. With this path I didn't create the folder before running the command, there is no need to run mkdir because the command will create the folder automatically.

云归处 2024-12-12 06:28:16

对于Linux
在终端使用时:

ssh-keygen -t ed25519 -C "<comment>"

这会生成新的建模密钥。或者可以创建为:

ssh-keygen -t rsa -b 2048 -C "any comment"

然后继续以下终端..根据要求为文件指定任何名称
再次使用空密码..并继续

然后转到 /home/user/.ssh/id_ed25519 或 /home/user/.ssh/id_rsa (是隐藏文件..通过执行 ctrl+h 来取消隐藏隐藏文件来查看)并复制到gitlab =>简介=>设置=> ssh =>;通过粘贴复制的密钥来创建新密钥,并注意:公钥始终以 ssh 开头。
享受!
帮助:gitlab-帮助

For Linux
on terminal use:

ssh-keygen -t ed25519 -C "<comment>"

this generate new modeled key. Or can create as:

ssh-keygen -t rsa -b 2048 -C "any comment"

Then continue following terminal.. give any name to the file as asked
Again follow it with empty passphrase..and continue

Then goto the /home/user/.ssh/id_ed25519 or /home/user/.ssh/id_rsa (is hidden file..look by doing ctrl+h to unhide hidden file) and copy it to gitlab => profile => setting => ssh => create new key there by pasting copied key and NOTE: public key always starts with ssh.
Enjoy!
Help:gitlab-Help

彡翼 2024-12-12 06:28:16

就我而言,只需使用 git-bash 进入 .ssh 目录

Users\User\.ssh

,然后尝试 ssh-keygen 命令来生成密钥,瞧,它成功了!

In my case just went to the .ssh directory with git-bash -

Users\User\.ssh

and then tried ssh-keygen command to generate the key and Voila, it worked!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文