I recently bought a laptop and wrote a script that sets up a reverse
ssh tunnel if a certain user logs in through GDM. I did this because I've had a laptop stolen in the past and would like to be prepared in case it happens again.
I put the script in the directory below which GDM runs as root whenever a user logins.
Here is the script itself:
if [[ "$(users)" = "user user" ]]; then while (( "$(netstat -an | grep -E "\:22[ \t]+" | grep ESTABLISHED | \ wc -l)" < "1" )) do ssh -fvN -p 22 -R tunnelport:localhost:sshdport email@example.com sleep 20 done fi
The script runs if I'm already logged in, but if I login through GDM the first
if statement fails. If I remove the
if statement then it hangs on the
ssh command. Any ideas on what I can do?