Reputation: 1763
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?
Upvotes: 58
Views: 83190
Reputation: 15726
There's a service "OpenSSH Authentication Agent (ssh-agent)" on your system.
To start it from powershell:
start-service ssh-agent
Then once it's running you can add your key like normal with ssh-add
ssh-add
Since git uses it's own ssh sometimes, you might also need to set it to Window's ssh. The forward slashes /
are important here.
git config --global core.sshCommand 'C:/Windows/System32/OpenSSH/ssh.exe'
To keep ssh-agent running this SuperUser question has more information: https://superuser.com/questions/1327633/how-to-maintain-ssh-agent-login-session-with-windows-10s-new-openssh-and-powers
Upvotes: 2
Reputation: 91
git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"
Configure globally to use OpenSSH agent. Add your keys with
ssh-add.exe <path to ssh key>
Upvotes: 9
Reputation: 48318
If you are using Windows' native implementation of OpenSSH with the native ssh-agent Windows service, make sure that git for Windows was configured to use that SSH implementation when you installed it:
If you used the bundled OpenSSH installation, git will default to that and will not use any keys imported into Windows' native ssh-agent service. You need to select "Use external OpenSSH" instead when prompted.
If you did not make this selection when installing, you should be able to fix that by just running the installer again.
Upvotes: 17
Reputation: 1485
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 CurrentUser
PowerShellGet\Install-Module posh-git -Scope CurrentUser
In your ps1 file:
Import-Module posh-git
Import-Module posh-sshell
Start-SshAgent
It should automagically pick up any key-files in your ~/.ssh
.
Upvotes: 21
Reputation: 4443
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://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops
Upvotes: 48
Reputation: 13
The issue is the git was unable to find the ssh_agent.exe which supplied the credentials The steps I followed are given below
$env:path += ";" + "C:\Program Files\Git\usr\bin"
Upvotes: 0
Reputation: 15697
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
Upvotes: 53