在Windows上使用git和ssh-agent [英] Using git with ssh-agent on Windows

查看:346
本文介绍了在Windows上使用git和ssh-agent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上。我安装了git和posh-git(用于Windows PowerShell的一些帮助程序)。我可以用 ssh-add 添加密钥,并且可以使用github和我的web服务器进行身份验证。我也可以使用PowerShell中的git来与我的仓库进行交互。



但是有一件事情我不能做:我在Atom编辑器中使用git-plus。我没有把它推到我的回购。我的问题是什么?

解决方案

posh-git git for windows 2.7 应该包含设置 ssh-agent 所需的一切。一旦你安装了模块,你可以使用类似的方式启动代理:

  Import-Module〜\Documents\WindowsPowerShell\\ \\Modules\posh-git\posh-git的
组锯齿的ssh-agent $ ENV:ProgramFiles\git\usr\bin\ssh-agent.exe
套装 - 别名ssh-add$ env:ProgramFiles \git\usr\bin\ssh-add.exe
Start-SshAgent -Quiet

然后你应该看到SSH_AUTH_SOCK环境变量设置为:

  C :\代码\ Go\src\bosun.org\cmd\scollector [master]> GCI ENV:SSH_AUTH_SOCK 

名称值
---- -----
SSH_AUTH_SOCK /tmp/ssh-6ORcVQvRBZ2e/agent.11668

运行命令时,git-plus atom包应该能够使用哪个。我可以使用Ctrl + Shift + H调出atom中的git菜单,选择push,然后推送到远程repo(如果失败,不会显示错误,但我推送的新分支在那里) 。

在打开atom之前,需要启动ssh-agent,以便设置SSH_AUTH_SOCK环境变量。如果它仍然不起作用,您可能需要在PowerShell中测试ssh以验证它可以不使用密码连接: -Alias ssh$ env:ProgramFiles \git\usr\bin\ssh.exe
ssh主机名


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.

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?

解决方案

posh-git and git for windows 2.7 should include everything you need to setup an ssh-agent. Once you have the module installed you can start the agent using something like:

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:

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).

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:

Set-Alias ssh "$env:ProgramFiles\git\usr\bin\ssh.exe"
ssh hostname

这篇关于在Windows上使用git和ssh-agent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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