Stopping SSH tunnel

I have initiated a tunnel for vncserver. now i want to stop it. is there any way except sleep option?

Just kill the ssh process. What do you mean by "sleep option"?

Or maybe you want to open an ssh session to forward the vnc port and then you want the terminal window to go away?

Oh! I just looked at the openssh faq and I see what you mean by "sleep option".
(OpenSSH FAQ for the curious bystander...) So, yes, you do want to forward a port without leaving a terminal running...

This isn't a really good answer, but it's what I do:

ssh -q -o BatchMode=yes -i $KEY -N -L $SOURCE.$PORT1:$DEST:$PORT2 $ACCNT@$OTHER_HOST &
SSHPID=$?

# start vncviewer

kill $SSHPID

That's from memory and untested, so consider it pseudo code.

1 Like

I save this is a script, since I regularly connect with vnc to machines behind a firewall:

#!/bin/sh
/usr/bin/ssh -p 69 -L 65530:127.0.0.1:65530 -R 65530:127.0.0.1:65531 -N -v -C -c blowfish user@somehost.com \
-L 5901/machine2/5900 -L 5900/machine1/5900 -L 5903/machine3/5900

It runs in the background after closing the terminal window, but it must be killed manually.