【问题标题】:Attempting to add my SSH key to the ssh-agent but getting 'no such file or directory.'尝试将我的 SSH 密钥添加到 ssh-agent 但得到“没有这样的文件或目录”。
【发布时间】:2021-10-07 03:32:29
【问题描述】:

以下是我创建和尝试添加 SSH 密钥的步骤,但我不确定我哪里出错了,非常感谢任何帮助! (我是新手,抱歉)

按照网上的说明,我首先使用以下代码生成了一个新的 shh-key:

$ ssh-keygen -t ed25519 -C "[my email]"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/Akiper/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in
Your public key has been saved in  .pub

等等

然后我确保 ssh-agent 在后台运行并尝试将我生成的 shh-key 添加到 shh-agent 但我收到以下错误:

$ eval `ssh-agent -s`
Agent pid 304

$ ssh-add ~/.ssh/id_ed25519
/c/Users/Akiper/.ssh/id_ed25519: No such file to directory

正如您在第三行代码中看到的,密钥保存在以下文件中:

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

正如您可以想象的那样,我很困惑为什么代码说它无法找到其中的关键,或者我可能错误地解释了代码。再次感谢任何帮助和建议。

谢谢。

【问题讨论】:

  • 在cmd窗口中:dir c:\Users\Akiper\.ssh;在 git-bash 中:ls ~/.ssh/ — 文件在吗?如果没有,那里有什么文件?
  • 查看ssh-keygen 输出的最后两行。发生了一些可疑的事情。
  • 您在按 Enter 输入文件名之前是否不小心输入了一个空格?看起来没有使用默认值。
  • @phd 当我输入时,我得到以下ls: cannot access `/c/Users/Akiper/.ssh/`: No such file or directory
  • 这个版本的ssh-keygen似乎有一个bug;它应该要么创建目录/c/Users/Akiper/.ssh/ 要么报告错误,而不是默默地做......不管它做了什么。

标签: git ssh


【解决方案1】:

确保您在 ~/.ssh/ 目录中没有任何预制的 ssh 密钥 然后试试这个 ssh-keygen -t rsa -b 4096 -C "email" 照常执行后续步骤 ed25519 是 2048 位的 rsa 密钥,而上面的是 4096 位。

【讨论】:

  • 非常感谢!有效!我检查了我是否有任何预制的 ssh 密钥,似乎我的代码中发生了一些事情,即使一切看起来都井然有序,密钥也从未保存过?也许我只是解释错了。再次感谢!
【解决方案2】:

就像@iceweasel 说的,检查 ~/.ssh/ 目录是否为空,删除任何预先存在的键。然后输入:

$ ssh-keygen -t rsa -b 2048 -C "email"

然后你会看到这样的输出:

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/name/.ssh/id_rsa):
                                                 leave this empty ^
Enter passphrase: 
     leave this empty ^
Enter same passphrase again:
             leave this empty ^
Your identification has been saved in /Users/name/.ssh/id_rsa 
Your public key has been saved in /Users/name/.ssh/id_rsa.pub

然后,在终端中输入cd ~/.ssh 并检查id_rsaid_rsa.pub 是否可用。 然后输入cat id_rsa.pub 并复制密钥。如果需要,请将该密钥添加到 GitHub 的 SSH 密钥中:您将找到指南 here。 要设置 git-agent,请在终端中运行 eval "$(ssh-agent -s)"。 后跟ssh-add ~/.ssh/id_rsa

完成所有这些步骤后,您就可以提交更改并将您的工作推送到远程仓库了。

【讨论】:

  • 谢谢你,你拯救了新开发者的一天!
猜你喜欢
  • 1970-01-01
  • 2021-06-23
  • 2021-04-20
  • 2017-05-27
  • 1970-01-01
  • 2019-01-17
  • 1970-01-01
  • 2021-11-05
  • 2018-06-25
相关资源
最近更新 更多