保存 ssh 密钥失败
我刚刚开始学习 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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”来完成此操作。从文件资源管理器(请注意末尾的第二个点,它将自动删除,并且需要创建一个开头有点的文件夹)。
我知道这是一个旧线程,但我认为答案可能对其他人有帮助。
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).I know this is an old thread, but I thought the answer might help others.
如果您更喜欢使用 GUI 创建密钥
有关 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
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
看起来您正在从 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.
我有同样的问题。我必须使用 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
您必须自己创建 .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
我刚刚在同样的问题上挣扎了一段时间(使用Mac)。这是我所做的,它终于奏效了:
(1) 确认 .ssh 目录存在:
(2) 只需在提示符下按 Enter 键即可接受所有默认值
您应该收到一条消息:
PS 如果您正在为 Rails 配置 git,请执行以下操作( 源):(
然后按 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:
(2) Accept all default values by just pressing enter at the prompt
You should get a message :
PS If you are configuring git for rails, do the following (source):
(then accept all defaults by pressing enter)
在 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 usingmkdir ".ssh"
command.After doing that I was able to use the ssh-keygen without any path problems.
我在 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.
您的方法在 Mac 上应该可以正常工作,但在 Windows 上,还需要两个额外的步骤。
将 id_rsa 密钥保存在此位置应该可以解决权限错误。
Your method should work fine on a Mac, but on Windows, two additional steps are necessary.
Saving the id_rsa key in this location should solve the permission error.
我遇到了同样的问题。
Windows 上的解决方案:
将“YOURUSERNAME”替换为您的 Windows 帐户名
mkdir .ssh
这将创建一个 .ssh 文件夹。
I faced the same problem.
Solution on windows:
Replace "YOURUSERNAME" with your windows account name
mkdir .ssh
This will create a .ssh folder.
对于 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 domkdir .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
对于 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...
在 Mac 上,您首先必须
cd ~/.ssh
然后您可以执行ssh-keygen
on Mac, you first have to
cd ~/.ssh
then you can dossh-keygen
在使用 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.
对于Linux
在终端使用时:
这会生成新的建模密钥。或者可以创建为:
然后继续以下终端..根据要求为文件指定任何名称
再次使用空密码..并继续
然后转到 /home/user/.ssh/id_ed25519 或 /home/user/.ssh/id_rsa (是隐藏文件..通过执行 ctrl+h 来取消隐藏隐藏文件来查看)并复制到gitlab =>简介=>设置=> ssh =>;通过粘贴复制的密钥来创建新密钥,并注意:公钥始终以 ssh 开头。
享受!
帮助:gitlab-帮助
For Linux
on terminal use:
this generate new modeled key. Or can create as:
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
就我而言,只需使用 git-bash 进入 .ssh 目录
,然后尝试 ssh-keygen 命令来生成密钥,瞧,它成功了!
In my case just went to the
.ssh
directory with git-bash -and then tried
ssh-keygen
command to generate the key and Voila, it worked!