Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
892 views
in Technique[技术] by (71.8m points)

powershell - Using git with ssh-agent on Windows

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...