Git Bash:无法打开与您的身份验证代理的连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24154816/
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
Git Bash: Could not open a connection to your authentication agent
提问by leipzy
I'm new to Github and Generating SSH Keys look a neccessity. And was informed by my boss about this, so I need to comply.
我是 Github 的新手,生成 SSH 密钥看起来很有必要。并且被我的老板告知了这件事,所以我需要遵守。
I successfully created SSH Key but when I'm going to add it to the ssh-agent
我成功创建了 SSH 密钥,但是当我要将其添加到 ssh-agent 时
this is what happens
这就是发生的事情
What seems to be the problem?
似乎是什么问题?
回答by Kritana
It seems you need to run ssh-agent
before using it:
看来你需要ssh-agent
在使用之前运行它:
eval `ssh-agent -s`
That question was answered in this topic: Could not open a connection to your authentication agent
该问题已在本主题中得到解答:无法打开与您的身份验证代理的连接
回答by derekmx271
I checked all the solutions on this post and the post that @kenorb referenced above, and I did not find any solution that worked for me.
我检查了这篇文章和上面@kenorb 引用的文章中的所有解决方案,但没有找到任何对我有用的解决方案。
I am using Git 1.9.5 Preview on Windows 7 with the following configuration: - Run Git from the Windows Command Prompt - Checkout Windows-style, commit Unix-style line endings
我在 Windows 7 上使用 Git 1.9.5 预览版,配置如下: - 从 Windows 命令提示符运行 Git - 签出 Windows 风格,提交 Unix 风格的行尾
I used the 'Git Bash' console for everything... And all was well until I tried to install the SSH keys. GitHub's documentation says to do the following (don't run these commands until you finish reading the post):
我使用了“ Git Bash”控制台来处理所有事情……一切都很好,直到我尝试安装 SSH 密钥。GitHub 的文档说要执行以下操作(在阅读完帖子之前不要运行这些命令):
Ensure ssh-agent is enabled:
If you are using Git Bash, turn on ssh-agent:If you are using another terminal prompt, such as msysgit, turn on ssh-agent:# start the ssh-agent in the background ssh-agent -s # Agent pid 59566
# start the ssh-agent in the background eval $(ssh-agent -s) # Agent pid 59566
确保 ssh-agent 已启用:
如果您使用的是 Git Bash,请打开 ssh-agent:如果您正在使用其他终端提示,例如 msysgit,请打开 ssh-agent:# start the ssh-agent in the background ssh-agent -s # Agent pid 59566
# start the ssh-agent in the background eval $(ssh-agent -s) # Agent pid 59566
Now of course I missed the fact that you were supposed to do one or the other. So, I ran these commands multiple times because the later ssh-add
command was failing, so I returned to this step, and continued to retry over and over.
当然,我错过了你应该做一个或另一个的事实。所以,我多次运行这些命令,因为后面的ssh-add
命令失败了,所以我回到了这一步,并继续一遍又一遍地重试。
This results in 1 Windows 'ssh-agent' process being created every single time you run these commands (notice the new PID every time you enter those commands?)
这会导致每次运行这些命令时都会创建 1 个 Windows 'ssh-agent' 进程(注意每次输入这些命令时的新 PID?)
So, Ctrl
+Alt
+Del
and hit End Process
to stop each 'ssh-agent.exe' process.
所以,Ctrl
+ Alt
+Del
和命中End Process
停止每个“ SSH-agent.exe”的过程。
Now that all the messed up stuff from the failed attempts is cleaned up, I will tell you how to get it working...
既然失败的尝试中所有混乱的东西都被清理干净了,我将告诉你如何让它工作......
In 'Git Bash':
在“ Git Bash”中:
Start the 'ssh-agent.exe' process
启动“ ssh-agent.exe”进程
eval $(ssh-agent -s)
And install the SSH keys
并安装 SSH 密钥
ssh-add "C:\Users\MyName\.ssh\id_rsa"
* Adjust the path above with your username, and make sure that the location of the*/.sshdirectory is in the correct place. I think you choose this location during the Git installation? Maybe not...
* 用您的用户名调整上面的路径,并确保* /.ssh目录的位置在正确的位置。我认为您在 Git 安装过程中选择了这个位置?也许不吧...
The part I was doing wrong before I figured this out was I was not using quotes around the 'ssh-add' location. The above is how it needs to be entered on Windows.
在我弄清楚之前我做错的部分是我没有在“ ssh-add”位置周围使用引号。以上是在Windows上需要输入的方式。
回答by Jhourlad Estrella
On Windows, you can use Runwith one of the below commands.
在 Windows 上,您可以通过以下命令之一使用Run。
For 32-Bit:
对于 32 位:
"C:\Program Files (x86)\Git\cmd\start-ssh-agent.cmd"
“C:\Program Files (x86)\Git\cmd\start-ssh-agent.cmd”
For-64 Bit:
For-64 位:
"C:\Program Files\Git\cmd\start-ssh-agent.cmd"
“C:\Program Files\Git\cmd\start-ssh-agent.cmd”
回答by Varus Septimus
Situation: MVS2017 App - Using 'Git Bash' on Windows 10 - Trying to connect to a BitBucket repository.
情况:MVS2017 应用程序 - 在 Windows 10 上使用“Git Bash” - 尝试连接到 BitBucket 存储库。
To be clear, when you install Git for Windows (https://git-scm.com/download/win), it comes with an utility called Git Bash.
需要明确的是,当您安装 Windows 版 Git ( https://git-scm.com/download/win) 时,它会附带一个名为 Git Bash 的实用程序。
So, I am in 'Git Bash', as follows:
所以,我在'Git Bash'中,如下:
Mike@DUBLIN MINGW64 ~/source/repos/DoubleIrish (master)
$ git remote add origin [email protected]:Guiness/DoubleIrish.git
$ git remote -v
origin [email protected]:Guiness/DoubleIrish.git (fetch)
origin [email protected]:Guiness/DoubleIrish.git (push)
Mike@DUBLIN MINGW64 ~/source/repos/DoubleIrish (master)
$ git push -u origin master
[...]
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Is the private key set up?
私钥设置好了吗?
$ ssh -V
OpenSSH_7.7p1, OpenSSL 1.0.2p 14 Aug 2018
$ ls -a ~/.ssh
./ ../ known_hosts
I can see that, at this point, my private key file(id_rsa
) is missing. So I add it:
(note: generating a pair of private-public keys is out of scope of my reply, but
I can say that in Linux, you can use ssh-keygen
for that.)
我可以看到,此时,我的私钥文件( id_rsa
) 丢失了。所以我添加了它:(注意:生成一对公私钥不在我的回复范围内,但我可以说在 Linux 中,你可以使用ssh-keygen
它。)
$ ls -a ~/.ssh
./ ../ id_rsa known_hosts
OK, let's proceed:
好的,让我们继续:
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-KhQwFLAgWGYC/agent.18320; export SSH_AUTH_SOCK;
SSH_AGENT_PID=17996; export SSH_AGENT_PID;
echo Agent pid 17996;
$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.
To solve this, I run:
为了解决这个问题,我运行:
$ ssh-agent bash
And then, again:
然后,再次:
$ ssh-add ~/.ssh/id_rsa
Identity added: /c/Users/Mike.CORP/.ssh/id_rsa (/c/Users/Mike.CORP/.ssh/id_rsa)
It worked for me. Hope this helps
它对我有用。希望这可以帮助
回答by Mihail Ignatiev
I would like to improve on the accepted answer
我想改进已接受的答案
Downsides of using .bashrc
with eval ssh-agent -s
:
使用.bashrc
with 的缺点eval ssh-agent -s
:
- Every git-bash will have it's own ssh-agent.exe process
- SSH key should be manually added every time you open git-bash
- 每个 git-bash 都有自己的 ssh-agent.exe 进程
- 每次打开 git-bash 都要手动添加 SSH 密钥
Here is my .bashrc
that will eradicate above downsides
这是我的.bashrc
,将消除上述缺点
Put this .bashrc
into your home directory (Windows 10: C:\Users\[username]\.bashrc
) and it will be executed every time a new git-bash is opened
and ssh-add
will be working as a first class citizen
将其.bashrc
放入您的主目录(Windows 10 C:\Users\[username]\.bashrc
:),每次打开新的 git-bash 时都会执行它,ssh-add
并将作为一等公民工作
Read #comments to understand how it works
阅读#comments 了解它是如何工作的
# Env vars used
# SSH_AUTH_SOCK - ssh-agent socket, should be set for ssh-add or git to be able to connect
# SSH_AGENT_PID - ssh-agent process id, should be set in order to check that it is running
# SSH_AGENT_ENV - env file path to share variable between instances of git-bash
SSH_AGENT_ENV=~/ssh-agent.env
# import env file and supress error message if it does not exist
. $SSH_AGENT_ENV 2> /dev/null
# if we know that ssh-agent was launched before ($SSH_AGENT_PID is set) and process with that pid is running
if [ -n "$SSH_AGENT_PID" ] && ps -p $SSH_AGENT_PID > /dev/null
then
# we don't need to do anything, ssh-add and git will properly connect since we've imported env variables required
echo "Connected to ssh-agent"
else
# start ssh-agent and save required vars for sharing in $SSH_AGENT_ENV file
eval $(ssh-agent) > /dev/null
echo export SSH_AUTH_SOCK=\"$SSH_AUTH_SOCK\" > $SSH_AGENT_ENV
echo export SSH_AGENT_PID=$SSH_AGENT_PID >> $SSH_AGENT_ENV
echo "Started ssh-agent"
fi
Also this script uses a little trick to ensure that provided environment variables are shared between git-bash instances by saving them into an .env
file.
此外,这个脚本使用了一个小技巧来确保提供的环境变量通过将它们保存到.env
文件中而在 git-bash 实例之间共享。
回答by Avi
I was struggling with the problem as well.
我也在努力解决这个问题。
After I typed $ eval 'ssh-agent -s' followed by $ssh-add ~/.ssh/id_rsa
在我输入 $ eval 'ssh-agent -s' 后跟 $ssh-add ~/.ssh/id_rsa
I got the same complain: "Could not open a connection to your authentication agent". Then I realize there are two different kind of quotation on my computer's keyboard. So I tried the one at the same position as "~":
$ eval ssh-agent -s
$ ssh-add ~/.ssh/id_rsa
我收到了同样的抱怨:“无法打开与您的身份验证代理的连接”。然后我意识到我的电脑键盘上有两种不同的引用。所以我在与“~”相同的位置尝试了一个: $ eval ssh-agent -s
$ ssh-add ~/.ssh/id_rsa
And bang it worked.
砰的一声,它奏效了。
回答by Zhang Qun
above solution doesn't work for me for unknown reason. below is my workaround which was worked successfully.
由于未知原因,上述解决方案对我不起作用。下面是我成功的解决方法。
1) DO NOTgenerate a new ssh key by using command ssh-keygen -t rsa -C"[email protected]"
, you can delete existing SSH keys.
1)不要使用命令生成新的 ssh 密钥ssh-keygen -t rsa -C"[email protected]"
,您可以删除现有的 SSH 密钥。
2) but use Git GUI, -> "Help" -> "Show ssh key" -> "Generate key", the key will saved to ssh automatically and no need to use ssh-add
anymore.
2)但使用Git GUI,->“帮助”->“显示ssh密钥”->“生成密钥”,密钥将自动保存到ssh,不再需要使用ssh-add
。
回答by user11767754
Try using cygwin instead of bash. that worked for me
尝试使用 cygwin 而不是 bash。这对我有用