尝试将我的 SSH 密钥添加到 ssh-agent,但得到“没有这样的文件或目录。”

问题描述 投票:0回答:3

以下是我创建并尝试添加 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):

正如你所想象的,我很困惑为什么代码说它找不到这样的密钥,或者我可能错误地解释了代码。再次感谢任何帮助和建议。

谢谢你。

git ssh
3个回答
6
投票

就像@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_rsa
id_rsa.pub
是否可用。 然后输入
cat id_rsa.pub
并复制密钥。如果需要,请在 GitHub 的 SSH 密钥中添加该密钥:您可以在here找到该指南。 要设置 git-agent,请在终端中运行
eval "$(ssh-agent -s)"
。 接下来是
ssh-add ~/.ssh/id_rsa

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


3
投票

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


0
投票

我也遇到了同样的问题,但在添加 ssh-add 时使用完整路径可以解决

ssh-add /Users/sakthi.n/.ssh/id_rsa_personal
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.