在Windows上启动Git Bash时运行SSH代理 [英] Running SSH Agent when starting Git Bash on Windows

查看:485
本文介绍了在Windows上启动Git Bash时运行SSH代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用git bash.我必须使用

I am using git bash. I have to use

eval `ssh-agent.exe`
ssh-add /my/ssh/location/

每次我开始新的git bash时.

every time when I start a new git bash.

有没有办法永久设置ssh代理?还是Windows有一个好方法 管理ssh密钥?

Is there a way to set ssh agent permanently? Or does windows has a good way to manage the ssh keys?

我是新手,请给我详细的教程,谢谢!

I'm a new guy, please give me detailed tutorial, thanks!

推荐答案

在git bash会话中,您可以将脚本添加到~/.profile~/.bashrc(

In a git bash session, you can add a script to ~/.profile or ~/.bashrc (with ~ being usually set to %USERPROFILE%), in order for said session to launch automatically the ssh-agent. If the file doesn't exist, just create it.

这就是GitHub在"使用SSH密钥短语".

This is what GitHub describes in "Working with SSH key passphrases".

"在适用于Windows的Git上自动启动ssh-agent 一节中有一个功能强大的脚本,可以检查该代理是否正在运行.下面仅是一个片段,有关完整的解决方案,请参见GitHub文章.

The "Auto-launching ssh-agent on Git for Windows" section of that article has a robust script that checks if the agent is running or not. Below is just a snippet, see the GitHub article for the full solution.

# This is just a snippet. See the article above.
if ! agent_is_running; then
    agent_start
    ssh-add
elif ! agent_has_keys; then
    ssh-add
fi

其他资源:

"让ssh-agent与从Windows命令外壳运行的git一起使用"也有类似的脚本,但是我d主要参考上面的GitHub文章,该文章更可靠且最新.

"Getting ssh-agent to work with git run from windows command shell" has a similar script, but I'd refer to the GitHub article above primarily, which is more robust and up to date.

这篇关于在Windows上启动Git Bash时运行SSH代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆