在 Windows 上将 git 与 ssh-agent 一起使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34638462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using git with ssh-agent on Windows
提问by LuMa
I'm on Windows. I installed git and posh-git (some helpers for Windows PowerShell). I can add keys with ssh-add
and can authenticate with github and my webserver. I can also use git from the PowerShell to interact with my repositories.
我在 Windows 上。我安装了 git 和 posh-git(Windows PowerShell 的一些帮助程序)。我可以添加密钥,ssh-add
并且可以使用 github 和我的网络服务器进行身份验证。我还可以使用 PowerShell 中的 git 与我的存储库进行交互。
But there is one thing I can't do: I use git-plus for the Atom editor. And I don't get it to push to my repo. What is my problem?
但是有一件事我不能做:我将 git-plus 用于 Atom 编辑器。而且我无法将其推送到我的回购中。我的问题是什么?
回答by Greg Bray
posh-gitand git for windows 2.7should include everything you need to setup an ssh-agent. Once you have the module installed you can start the agent using something like:
适用于 Windows 2.7 的posh-git和git应该包括设置ssh-agent所需的一切。安装模块后,您可以使用以下内容启动代理:
Import-Module ~\Documents\WindowsPowerShell\Modules\posh-git\posh-git
Set-Alias ssh-agent "$env:ProgramFiles\git\usr\bin\ssh-agent.exe"
Set-Alias ssh-add "$env:ProgramFiles\git\usr\bin\ssh-add.exe"
Start-SshAgent -Quiet
You then should see the SSH_AUTH_SOCK environmental variable is set:
然后您应该看到 SSH_AUTH_SOCK 环境变量已设置:
C:\Code\Go\src\bosun.org\cmd\scollector [master]> gci env:SSH_AUTH_SOCK
Name Value
---- -----
SSH_AUTH_SOCK /tmp/ssh-6ORcVQvRBZ2e/agent.11668
Which the git-plus atom package should be able to use when you run commands. I was able to use Ctrl+Shift+H to bring up the git menu in atom, select push, and then push to a remote repo (not it doesn't display errors if it fails, but the new branch I pushed was there).
当您运行命令时,git-plus atom 包应该能够使用。我能够使用 Ctrl+Shift+H 在 atom 中调出 git 菜单,选择 push,然后推送到远程仓库(如果失败,它不会显示错误,但我推送的新分支就在那里) .
The ssh-agent needs to be started BEFORE you open atom so that the SSH_AUTH_SOCK environmental variable is set. If it still doesn't work you may want to test ssh in PowerShell to verify that it can connect without a password:
ssh-agent 需要在打开 atom 之前启动,以便设置 SSH_AUTH_SOCK 环境变量。如果它仍然不起作用,您可能需要在 PowerShell 中测试 ssh 以验证它是否可以在没有密码的情况下连接:
Set-Alias ssh "$env:ProgramFiles\git\usr\bin\ssh.exe"
ssh hostname
回答by Garry Polley
You can get the ssh-agent running using the command that comes with Git for Windows in powershell:
您可以在 powershell 中使用 Git for Windows 附带的命令运行 ssh-agent:
start-ssh-agent.cmd
That will start up the ssh-agent.
这将启动 ssh-agent。
Then you can add your key with
然后你可以添加你的密钥
ssh-add ~/.ssh/namneOfPrivateKey
Found that here: https://docs.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops
在这里发现:https: //docs.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops
回答by Naveen Muralidharan
The issue is the git was unable to find the ssh_agent.exe which supplied the credentials The steps I followed are given below
问题是 git 无法找到提供凭据的 ssh_agent.exe 下面给出了我遵循的步骤
- Searched the ssh_agent.exe file drive
- Added the path as environment path int the profile.example.ps1 file
- 搜索 ssh_agent.exe 文件驱动器
- 在 profile.example.ps1 文件中添加了路径作为环境路径
$env:path += ";" + "C:\Program Files\Git\usr\bin"
$env:path += ";" + "C:\Program Files\Git\usr\bin"