Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to access a SSH service with pass-phrase protected private key in Windows using ssh-agent.exe.

So far I able to utilize ssh-agent.exe by changing environment setting in my home account manually to set an environment variable as follow:

SSH_AUTH_SOCK = %TEMP%\ssh-Co312dEaE\agent.1208

The environment variable should not set in cmd box or else other process accessing ssh.exe may not recognize the environment variable. It has to set in Windows user account.

The above setting need to redo again after a machine reboot.

Is there any good way to automate the launching of ssh-agent and setting the SSH_AUTH_SOCK in the context of native Windows session?

share|improve this question

When you run ssh-agent you should save the SSH_AUTH_SOCK and SSH_AGENT_PID environment variables to a file, and use them to see if the agent is already running.

You need to run cygwin once to start the agent, but after that it doesn't have to be running. This could probably be setup as a service as well.

To run ssh-agent.exe in the background I have added the following to .bashrc

# Store env variables
# Include env variables if they exist
[ -f "$run_ssh_agent" ] && . "$run_ssh_agent" >/dev/null 2>&1
# Test if agent is running
if kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then
    # Agent is running
    echo Agent pid $SSH_AGENT_PID
    # Agent is not running, launch it and store env variables
    ssh-agent -s > "$run_ssh_agent"
    . "$run_ssh_agent"
    # Add private keys
# List loaded identities
ssh-add -l

This doesn't quite accomplish what you are looking for (running ssh-agent without cygwin), but it works perfectly for storing keys in memory.

share|improve this answer

I've created a pretty involved script for Windows cmd.exe along with a registry hack that can be used to make it autorun in (most) ever command shell launched.

Basically, it does similar things as a Unix script to do the same would.. except that it sets a specific socket file to be used, instead of attempting to parse the ssh-agent output ..

100% windows cmd script except for ssh, ssh-agent, and ssh-add.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .