Tom Badran wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>I have two ssh tunnels that are run in my .bashrc file so that i can have 
>secure pop/smtp.
>
>The system works great, but it does have one setback, each time i open a new 
>terminal (which obviously runs bash) i get more and more ssh processes 
>running.
>
>How can i set this up so that the tunnels are only setup if they need to be? 
>Is there a way to make the ssh command run only if the tunnels do not exist? 
>I read somewhere that you can add tunnels to the .ssh/config file but i have 
>found no documentation detailing this.
>
This is script what I use to start a ssh-agent (script placed in 
/etc/profile.d) to hold (even between different login sessions) any keys 
I load. I had to hack some X startup script to load /etc/profile.d 
because it's not done by default.
The script works fine for me as I am the only physical user of my 
computer with several accounts.  On a real multiuser machine both you 
and root user can acces keys loaded to your agent. There may be similar 
problem with SSH tunnels.

Hope this helps.
#!/bin/bash

agentinfo=$HOME/.ssh-agent-info
minuser=500

if [ $EUID -lt $minuser ] ; then return ; fi

if [ "$SSH_AUTH_SOCK" ] && ssh-add -l 2>/dev/null; then 
        set +x
        return ;
fi

if [ -s $agentinfo ] ; then 
        . $agentinfo
        if ps -A | grep "$SSH_AGENT_PID" >/dev/null \
            && [ -e "$SSH_AUTH_SOCK" ] ; then
                if ssh-add -l 2>/dev/null; then 
                        set +x
                        return ;
                else
                        rm -f $SSH_AUTH_SOCK ;
                fi
        fi
fi

ssh-agent > $agentinfo
. $agentinfo

unset agentinfo minuser
Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to