使用cygwin ssh-agent正在运行,但git仍提示输入密码 [英] Using cygwin ssh-agent is running but git is still prompting for passphrase
问题描述
我在Windows 7上使用cygwin作为终端.我发现了一些在cygwin中运行ssh-agent的建议,因此不必每次运行git fetch/pull/push时都输入密码.我将以下内容添加到我的.bash_profile中,并重新启动了cygwin会话:
I'm using cygwin as my terminal on Windows 7. I have found several suggestions to run ssh-agent in cygwin so I don't have to enter my password every time I run a git fetch/pull/push. I added the following to my .bash_profile and restarted my cygwin session:
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent -s | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
看来ssh-agent和ssh-add已成功运行,但仍然提示我输入密码.
It looks as if the ssh-agent and ssh-add are run successfully, but I am still prompted for my password.
Initialising new SSH agent...
succeeded
Enter passphrase for /cygdrive/c/Users/<username>/.ssh/id_rsa:
Identity added: /cygdrive/c/Users/<username>/.ssh/id_rsa (/cygdrive/c/Users/<username>/.ssh/id_rsa)
$ ssh-add -l
2048 <fingerprint> /cygdrive/c/Users/<username>/.ssh/id_rsa (RSA)
$ git fetch --all
Fetching origin
Enter passphrase for key '/c/Users/<username>/.ssh/id_rsa':
事实上,我的git连接(已编辑的私人信息)使用的是SSH,而不是HTTPS:
I am in fact using SSH and not HTTPS for my git connection (redacted private info):
$ git remote -v
origin ssh://git@XXX/XXX.git (fetch)
origin ssh://git@XXX/XXX.git (push)
我找到的与此问题最接近的问题是以下问题:
The closest problem I've found for this issue is the following question:
但是,我没有在/git/bin下重命名ssh.
However, I didn't rename my ssh under /git/bin.
有关如何诊断此问题的任何建议?谢谢!
Any suggestions on how to diagnose this issue? Thanks!
推荐答案
问题仍然存在.似乎它与不同的路径有关,并且尚未修复. 您可以考虑使用 期望 作为ssh-agent的替代方法for 使用密码登录互动.
The problem is still remain. Seems it is related to the different paths and hasn't been fixed yet. You may consider to use expect as an alternatif to ssh-agent for login with passphrase interaction.
在Linux中,它的安装方式如下:
In Linux it use to be installed like this:
$ sudo apt-get update
$ apt-get install --assume-yes --no-install-recommends apt-utils expect
在cygwin中,您可以在Tcl
下找到它:
In cygwin you may find it under Tcl
:
这是如何使用它的简单步骤.
Here is a simple step on how to use it.
创建一个文件,让它找到并命名为~/.expect_push
Create a file, lets locate it and name ~/.expect_push
#!/usr/bin/expect -f
spawn git push origin master
expect "Username for 'https://github.com':"
send "<username>\n";
expect "Password for 'https://<username>@github.com':"
send "<password>\n";
interact
将上面的<username>
和<password>
更改为您的登录ID,并注意以下几点:
Change the above <username>
and <password>
to your login id with following notes:
- 修改内容与您的git登录交互完全相同.
- 如果您的
<password>
包含字符$
,则将其作为\$
放置,否则身份验证将失败. - 例如,如果您的密码
mypa$$word
,则将<password>
设置为mypa\$\$word
.
- Modify the contents follow precisely to your git login interaction.
- If your
<password>
contain the char$
put it as\$
otherwise the authentication will be failed. - For example if your password
mypa$$word
then put<password>
asmypa\$\$word
.
创建另一个文件~/.git_push
#!/usr/bin/bash
git remote set-url origin git@github.com:<username>/<repo>.git
git add .
git commit -m "my test commit using expect"
expect ~/.ssh/.expect_push
使它们可执行,并在/bin
$ chmod +x ~/.expect_push
$ chmod +x ~/.git_push
$ cd /bin
$ ln -s ~/.git_push push
然后您可以push
到遥控器,而无需填写用户名和密码或密码
Then you can push
to the remote without need to fill in username and password or passphrase
$ cd /path/to/your/git/folder
$ push
这篇关于使用cygwin ssh-agent正在运行,但git仍提示输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!