在 Windows 上启动 Git Bash 时运行 SSH 代理 [英] Running SSH Agent when starting Git Bash on Windows
问题描述
我正在使用 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代码>(
~
通常设置为 %USERPROFILE%
),以便所述会话自动启动 ssh-agent
.如果文件不存在,只需创建它.
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".
Auto-launching ssh-agent on Git for Windows" 这篇文章的部分有一个强大的脚本来检查代理是否正在运行.下面只是一个片段,完整的解决方案见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 run" 有一个类似的脚本,但我'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屋!