gpt4 book ai didi

windows - 在 Windows 上启动 Git Bash 时运行 SSH Agent

转载 作者:可可西里 更新时间:2023-11-01 11:52:56 29 4
gpt4 key购买 nike

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

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

每次我启动一个新的 git bash 时。

有没有办法永久设置 ssh 代理?或者windows有什么好办法管理 ssh key ?

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

最佳答案

2013:在 git bash session 中,您可以将脚本添加到 ~/.profile~/.bashrc ( with ~ being usually set to %USERPROFILE% ) , 为了使所述 session 自动启动 ssh-agent
如果该文件不存在,则创建它。

这就是 GitHub 在“Working with SSH key passphrases”中描述的内容。

该文章的“Auto-launching ssh-agent on Git for Windows”部分有一个强大的脚本,用于检查代理是否正在运行。
以下只是一个片段,有关完整解决方案,请参阅 GitHub 文章。

# 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

其他资源:

Getting ssh-agent to work with git run from windows command shell”有一个类似的脚本,但我主要引用上面的 GitHub 文章,它更可靠且最新。


hardsettingthe comments (2018) 中添加:

If you want to enter the passphrase the first time you need it, and not when opening a shell, the cleanest way to me is:

This way you don't even have to remember running ssh-add.


Taothe comments (2022) 中添加:

It's worth noting why this script makes particular sense in Windows, vs (for example) the more standard linuxey script noted by @JigneshGohel in another answer:

By not relying on the SSH_AGENT_PID at all, this script works across different msys & cygwin environments.
An agent can be started in msys2, and still used in git bash, as the SSH_AUTH_SOCK path can be reached in either environment.
The PID from one environment cannot be queried in the other, so a PID-based approach keeps resetting/creating new ssh-agent processes on each switch.

关于windows - 在 Windows 上启动 Git Bash 时运行 SSH Agent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18404272/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com