Jac*_*cko 36 git ssh-agent git-bash
我安装了msysgit,使用OpenSSH.我正在连接一个gitosis回购.从git bash,我创建了一个.profile
文件,每次打开git bash时运行ssh-agent(如果尚未运行),使用此脚本
SSH_ENV=$HOME/.ssh/environment
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | 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
Run Code Online (Sandbox Code Playgroud)
我也在使用git扩展,它从Windows命令提示符运行git命令,而不是git bash.所以,ssh没有看到正在运行的ssh-agent.有可能解决这个问题吗?
Fer*_*nto 45
我遇到了和你一样的问题,然后我尝试添加这段代码
#! /bin/bash
eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa
Run Code Online (Sandbox Code Playgroud)
到.bashrc
我的主目录中的文件.它的工作原理!
Bra*_*iam 26
对于msysgit,您可能需要修改https://help.github.com/articles/working-with-ssh-key-passphrases提供的解决方案.
declare -x SSH_ENV="$HOME/.ssh/environment"
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
echo succeeded
chmod 600 "$SSH_ENV"
. "$SSH_ENV" > /dev/null
ssh-add
}
# test for identities
function test_identities {
# test whether standard identities have been added to the agent already
ssh-add -l | grep "The agent has no identities" > /dev/null
if [ $? -eq 0 ]; then
ssh-add
# $SSH_AUTH_SOCK broken so we start a new proper agent
if [ $? -eq 2 ];then
start_agent
fi
fi
}
# check for running ssh-agent with proper $SSH_AGENT_PID
if [ -n "$SSH_AGENT_PID" ]; then
ps -f -u $USERNAME | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null
if [ $? -eq 0 ]; then
test_identities
fi
else
if [ -f "$SSH_ENV" ]; then
. "$SSH_ENV" > /dev/null
fi
ps -f -u $USERNAME | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null
if [ $? -eq 0 ]; then
test_identities
else
start_agent
fi
fi
Run Code Online (Sandbox Code Playgroud)
你可能会注意到我做的唯一改变是在ps调用中,因为msysgit不使用-U但是-u
Cu7*_*4ss 23
即使你已经解决了它...使用eval
命令使ssh_agent
过程坚持:
eval `ssh-agent.exe`
Run Code Online (Sandbox Code Playgroud)
然后使用ssh-add添加所需的密钥.
Tho*_*ran 10
在Windows 10上,这对我有用
touch ~/.profile
start ~/.profile
打开 .profile
.profile
#! /bin/bash
eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa
Run Code Online (Sandbox Code Playgroud)
这是基于这个答案.唯一的区别是,.bashrc
没有工作,而是.profile
工作.
您可以使用源代码来包装 git 可执行文件.profile
,从而ssh-agent
加载环境变量。
要么将一个脚本放在git
路径中比真实 git 更早的目录中调用,要么配置 git 扩展以调用包装器来代替真实 git。
归档时间: |
|
查看次数: |
68257 次 |
最近记录: |