Skip to content

Instantly share code, notes, and snippets.

@krishnact
Last active January 8, 2019 14:23
Show Gist options
  • Save krishnact/ed69fae0d2635655dbf2c6b0fccf128e to your computer and use it in GitHub Desktop.
Save krishnact/ed69fae0d2635655dbf2c6b0fccf128e to your computer and use it in GitHub Desktop.
How to use ssh agent in cygwin.
#!/bin/bash
#name this file as ~/bin/checkSshAgent.sh and put at the end of your ~/.bash_profile as shown below (remove the ##)
##
## . ~/bin/checkSshAgent.sh
##
AGENT_PID=`ps -ef | grep ssh-agent | grep -v grep | awk '{print $2;}'`
if [ -f ~/.ssh/agent-info ]
then
echo Agent info exists
else
echo SSH_AGENT_PID=xx0 > ~/.ssh/agent-info
fi
AGENT_PID_PUBLISHED=`cat ~/.ssh/agent-info | grep SSH_AGENT_PID | tr '=;' ' ' | awk '{print $2;}'`
if [ "x${AGENT_PID}" = "x${AGENT_PID_PUBLISHED}" ]
then
echo Using existing Agent
else
echo $AGENT_PID | xargs -n 1 kill -9
ssh-agent > ~/.ssh/agent-info
. ~/.ssh/agent-info
ssh-add ~/.ssh/id_rsa
fi
chmod 700 ~/.ssh/agent-info
. ~/.ssh/agent-info
@krishnact
Copy link
Author

Last few lines of your bash_profile may look something like this after adding the checkAgent.sh file.

# Set INFOPATH so it includes users' private info if it exists
# if [ -d "${HOME}/info" ]; then
#   INFOPATH="${HOME}/info:${INFOPATH}"
# fi
. ~/bin/checkSshAgent.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment