I'm using this ssh command:
ssh -fnN -L $LOCALPORT:$REMOTEHOST:$REMOTEPORT $HOST
This creates my ssh connection in the background and forwards that port to the remote host through another host. This is great, and allows me to use my service behind a firewall by connecting to a server which can access both networks.
I need to stop this ssh connection when done, and I'm not sure how.
Find the
PID
with theps
command and send it a QUIT signal with thekill
command.Find the
PID
with:Send the
QUIT
signal with:The best solution I found is following to kill all the tunnels:
ps -o pid,cmd|grep "ssh -L"|grep -v grep|awk '{print $1}'|xargs kill