Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'ssh-agent reused' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
ssh-agent reused
Authored by: osahner on Feb 17, '02 06:41:40AM
I did a small (bash) function that avoid starting mutiple ssh-agents.
Just add the following code to your ~/.bashrc
#############################################
function sshagent () {
	SSHAGENT_ENVFILE=~/.ssh/ssh-agent.sh
	
	if [ "${1}" = "stop" ]; then
		echo -n "SSH-AGENT: "
		eval `ssh-agent -k`
		if [ -e "${SSHAGENT_ENVFILE}" ]; then
			rm ${SSHAGENT_ENVFILE}
		fi
	else
		echo -n "SSH-AGENT: "
		if [ -e "${SSHAGENT_ENVFILE}" ]; then
			source "${SSHAGENT_ENVFILE}"
		else 
			ssh-agent -s > ${SSHAGENT_ENVFILE}
			source "${SSHAGENT_ENVFILE}"
			ssh-add ~/.ssh/id_dsa ~/.ssh/id_rsa
		fi
	fi
}

sshagent start
##############################################
Now everytime you open a new Terminal the function checks if there is already a running ssh-agent. If Yes source the ENVIROMENT stored in ~/.ssh/ssh-agent.sh else start one.

[ Reply to This | # ]