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


Click here to return to the 'Run ssh-agent and Aqua without additional software' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Run ssh-agent and Aqua without additional software
Authored by: kidtexas on Jul 19, '04 04:10:11PM
After trying out several of the GUI versions of ssh-agent, I decided to pursue the command line route. Here is a copy of my .login (tcsh) that does the following: 1. checks to see if the ssh-agent sock is up and running - if its not, it starts it. 2. if the sock is there, but the file that holds the PID of ssh-agent is not, it recreates that pidfile 3. sets an env variable if the pidfile is there.

set sshAgent=/usr/bin/ssh-agent
set tmpFile = exportAgentEnv
set PIDFile = $HOME/.ssh/sshAgentPID

# Start an ssh-agent for global use
if ( -x "/usr/bin/ssh-agent" ) then
	if ( ! -e "$SSH_AUTH_SOCK" ) then	
		set OrigUmask=`umask`
		umask 077
		$sshAgent -a $SSH_AUTH_SOCK -c | head -2 > $tmpFile
		source $tmpFile
#		tail -n 1 $tmpFile > $PIDFile
		echo $SSH_AGENT_PID >$PIDFile
		rm $tmpFile
		echo "ssh-agent started [${SSH_AGENT_PID}]"
		umask $OrigUmask
		ssh-add
	endif
endif

if ( -e "$SSH_AUTH_SOCK" ) then	
	if ( ! -e "$PIDFile" ) then
		set sshpid=`ps x| grep ssh-agent | grep -v grep | awk '{print $1}'`
		echo $sshpid> $PIDFile
	endif
endif

# Read in ssh-agent PID
if (-e $PIDFile) then
	set sshpid=`head $PIDFile`
	setenv SSH_AGENT_PID $sshpid
#	source $PIDFile
endif
On logout, I have the following script running from a logout hook:

#! /bin/sh
if [ -e "$HOME/.ssh/sshAgentPID" ]; then
        SSH_AGENT_PID=`head $HOME/.ssh/sshAgentPID`
        echo "$SSH_AGENT_PID"
        echo "killing ssh agent [${SSH_AGENT_PID}]"
        kill $SSH_AGENT_PID 
        rm $HOME/.ssh/sshAgentPID
fi
I decided to implement the logout hook as detailed in the 3 part ssh-agent tutorial on this site. These 2 scripts were also adapted so they could be called up on the command line. The logout can be run exactly as is. The start script was adapted for sh (instead of csh):

#!/bin/sh

sshAgent=/usr/bin/ssh-agent
tmpFile=exportAgentEnv
PIDFile=$HOME/.ssh/sshAgentPID


# Start an ssh-agent for global use
if [ -x "/usr/bin/ssh-agent" ]; then
	if [ ! -e "$SSH_AUTH_SOCK" ]; then	
		OrigUmask=`umask`
		umask 077
		$sshAgent -a $SSH_AUTH_SOCK -s | head -2 > $tmpFile
		source $tmpFile
#		tail -n 1 $tmpFile > $PIDFile
		echo $SSH_AGENT_PID >$PIDFile
		rm $tmpFile
		echo "ssh-agent started [${SSH_AGENT_PID}]"
		umask $OrigUmask
		if [ -e $PIDFile ]; then
			sshpid=`head $PIDFile`
 			SSH_AGENT_PID=$sshpid
		 	export SSH_AGENT_PID
		fi
		ssh-add
	fi
fi

if [ -e "$SSH_AUTH_SOCK" ]; then	
	if [ ! -e "$PIDFile" ]; then
		sshpid=`ps x| grep ssh-agent | grep -v grep | awk '{print $1}'`
		echo $sshpid> $PIDFile
	fi
fi

if [ -e $PIDFile ]; then
	sshpid=`head $PIDFile`
 	SSH_AGENT_PID=$sshpid
 	export SSH_AGENT_PID
#	source $PIDFile
fi
This setup is also compatible with ssh-agent -k. While the above mentioned 3 part ssh-agent tutorial on this site is more integrated (the agent sock changes with each startup and is integrated with keychain) as a whole into the OS X experience, my setup is a little more terminal friendly. One does not have to be logged into the GUI for it to work, and one can also start and stop it at will - enabling one to hook into the sleep mechanism using other utilities if desired. Anyway, the main reason I was posting it is because these scripts do work with tcsh and os x and offer another option to the others mentioned.

[ Reply to This | # ]