How do I stop my ssh tunnel when it is in the background?
Solution 1:
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>
Solution 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
- Gets id and command of all processes
- Filter for ssh -L
- gets the process id and kills it