Using git with ssh-agent on Windows
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-gitSet-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_SOCKName 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
You can get the ssh-agent running using the command that comes with Git for Windows in powershell:
start-ssh-agent.cmd
That will start up the 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
Since a couple of years, the ssh part has been separated from posh-git
, and is now available through posh-sshell
.
To install:
PowerShellGet\Install-Module posh-sshell -Scope CurrentUserPowerShellGet\Install-Module posh-git -Scope CurrentUser
In your ps1 file:
Import-Module posh-gitImport-Module posh-sshellStart-SshAgent
It should automagically pick up any key-files in your ~/.ssh
.