openssh in Windows 7, run ssh-add once for all cmd instances

4

1

I have installed openSSH as part of the latest cygwin distribution. My goal is to use the ssh-agent from native window console (cmd) in order to login passwordless in a various number of Linux machines.

I have generated the keys and uploaded them to the appropriate directories in the remote hosts and everything works fine.

The only issue I have is that everytime I open a new cmd I have to run 'ssh-add', enter the passphrase and then I am able login passwordless in the remote hosts. Is there a way to overcome this problem? The ideal solution would be to run ssh-add only once.

fyi: I'm opening the cmd as an argument to the ssh-agent: 'ssh-agent cmd'

nonouco

Posted 2012-09-26T13:28:24.247

Reputation: 183

a small update: cygwin does not provide keychain as an .exe, thus I cannot use it in order to store my passwords. So I had to use just an empty passphrase in order to avoid typing the passphrase everytime or making an ssh-add everytime I started a new cmd. – nonouco – 2012-10-02T09:14:19.047

Answers

2

I actually created a tool called "ssh-agent-helper" that invokes ssh-agent and makes it available globally, so that, you can use ssh-add, ssh or git from any terminal e.g. CMD, Bash, PowerShell etc without any configuration.

You can find it here: https://github.com/raeesbhatti/ssh-agent-helper

Raees Iqbal

Posted 2012-09-26T13:28:24.247

Reputation: 121

Thanks a ton!! Was thinking about writing my own wrapper, this saved me a lot of time! Can't believe that's not built in the Windows version of OpenSSH (needed and works in Windows 10 also) – v01pe – 2017-08-23T13:11:08.027

-1

You will not be able to run ssh from the native command window. You will need to run the Cygwin bash "window" in order to run any of the Cygwin binaries.

Having said that, in the Cygwin bash "windows", you need to save the output of ssh-agent to a file and then source that file into any of the login scripts where you want to use the cached credentials. In the first "window", run:

$ ssh-agent >your_save_file     # Starts ssh-agent, saves shell variables
$ . your_save_file              # Loads saved shell variables into current shell
$ ssh-add                       # Adds keys into ssh-agent

In each of the others, run:

$ . your_save_file

All of the "windows" and child processes started after the . your_save_file command is run will be able to use the credentials cached in ssh-agent. Any time that the ssh-agent is stopped or killed, or after a system reboot, you will need to run the first set of commands again. If you are in doubt about whether or not the cached credentials are available in a particular shell, run

$ ssh-add -l            # Show list of loaded keys in ssh-agent

Yedric

Posted 2012-09-26T13:28:24.247

Reputation: 649

@Yedric: You can do the first step in a single command, with no temporary file: eval $(ssh-agent) – MikeK – 2014-09-17T15:48:48.027

ssh does work in cmd.exe, the question is if ssh-agent can also work somehow. – amenthes – 2014-10-02T09:53:09.283

This is wrong. I have been using cygwin's ssh tools from both cmd and powershell with no issues. – Asad Saeeduddin – 2014-11-15T21:22:05.097

@MikeK: Yes, you can, however, that does not allow other processes to use the ssh-agent. By saving to a file, you can source that file in other shells to provide access to the same ssh-agent . – Yedric – 2014-12-17T17:18:31.653

thanks for your answer. However I am able to run ssh and other cygwin .exe files. Actually, I can connect to remote hosts using cygwin's ssh from windows native cmd. – nonouco – 2012-10-01T15:31:48.563