16

On my Ubuntu machine, I simply use Keychain to maintain a single ssh-agent which stays logged in.

I'd like something similar to that on Windows now that OpenSSH is natively included. I was using Git Bash with the well-known if [ -z "$SSH_AUTH_SOCK" ] ; then ... script but this resulted in many ssh agents being opened, I knew it was advised against (partly due to this blog post: http://rabexc.org/posts/pitfalls-of-ssh-agents) - which is what made me get Keychain for Ubuntu. Another reason for not using this any more is that I'm moving to PowerShell as my main shell.

But I'm not sure how to achieve the same kind of thing on Windows specifically with PowerShell and with Win32-OpenSSH.

Thanks!

13

You must configure OpenSSH Authentication Agent service to automatically start (or you can start it manually everytime when opening your powershell for the first time: Start-Service ssh-agent).

After that, you need to ssh-add C:\path\to\your\ssh\key\id_rsa only once. After that, everytime the ssh-agent is started, the key will be there. You can check with ssh-add -l.

EDIT: To have SSH agent to automatically start with Windows, you can run Set-Service ssh-agent -StartupType Automatic on a super-user powershell prompt.

|improve this answer|||||
  • Could you please add details on how to get ssh-agent to start automatically? – Mark Woon May 8 '19 at 1:12
  • @MarkWoon I just edited my answer with that. – Davi Koscianski Vidal May 13 '19 at 13:59
  • 2
    This does not seem to work -- the Set-Service has no apparent effect, and the manual Start-Service, while it starts something, is also ineffective -- any ssh-add command thereafter fails with "communication with agent failed"... – Chris Dodd Jul 29 '19 at 20:18
  • * In the startmenu search for "Services" * Double click on "OpenSSH Authentication Agent" * Set the startup type to "Automatic" * Click "Start" * Click Ok and Exit * * Now go to PowerShell and add your key with "ssh-add" * After that the agent will remember your key when you need it :) – Esben Andersen Aug 30 '19 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.