Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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
run_ssh_agent="${HOME}/.ssh/agent-for-${HOSTNAME}.pid"
#
# 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
else
    #
    # Agent is not running, launch it and store env variables
    ssh-agent -s > "$run_ssh_agent"
    . "$run_ssh_agent"
    #
    # Add private keys
    ssh-add
fi
#
# 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.

https://github.com/ericblade/ssh-agent-cmd

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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