在 Windows 上将 git 与 ssh-agent 结合使用 [英] Using git with ssh-agent on Windows

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

问题描述

我使用的是 Windows.我安装了 git 和 posh-git(Windows PowerShell 的一些帮助程序).我可以使用 ssh-add 添加密钥,并且可以使用 github 和我的网络服务器进行身份验证.我还可以使用 PowerShell 中的 git 与我的存储库进行交互.

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.

但是有一件事我不能做:我将 git-plus 用于 Atom 编辑器.而且我无法将其推送到我的回购中.我的问题是什么?

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-gitgit for windows 2.7 应该包括设置 ssh-agent.安装模块后,您可以使用以下内容启动代理:

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 ~DocumentsWindowsPowerShellModulesposh-gitposh-git
Set-Alias ssh-agent "$env:ProgramFilesgitusrinssh-agent.exe"
Set-Alias ssh-add "$env:ProgramFilesgitusrinssh-add.exe"
Start-SshAgent -Quiet

然后您应该看到 SSH_AUTH_SOCK 环境变量已设置:

You then should see the SSH_AUTH_SOCK environmental variable is set:

C:CodeGosrcosun.orgcmdscollector [master]> gci env:SSH_AUTH_SOCK

Name                           Value
----                           -----
SSH_AUTH_SOCK                  /tmp/ssh-6ORcVQvRBZ2e/agent.11668

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

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

ssh-agent 需要在打开 atom 之前启动,以便设置 SSH_AUTH_SOCK 环境变量.如果它仍然不起作用,您可能需要在 PowerShell 中测试 ssh 以验证它是否可以在没有密码的情况下连接:

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:ProgramFilesgitusrinssh.exe"
ssh hostname

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

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