9

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.

1

2 Answers 2

3

Find the PID with the ps command and send it a QUIT signal with the kill command.

Find the PID with:

ps -o pid,cmd | grep ssh

Send the QUIT signal with:

kill -QUIT <pid>
2
2

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

  1. Gets id and command of all processes
  2. Filter for ssh -L
  3. gets the process id and kills it

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .