Table of Contents
In this article, I will show you how to create a file to delete ssh tunnel.
You understand this simple, in the previous article, you successfully created the file containing the ssh tunnel information. You use it to create tunnels to use.
So when you’re done using it, you need to delete that tunnel (although this is not required).
Script to delete ssh tunnel
Below is the demo content of the script file used to delete the ssh tunnels.
#!/bin/bash
options=(
"KILL 10000 : SERVER RDP 01 : 3389"
"KILL 10001 : SERVER RDP 02 : 3389"
"KILL 10002 : SERVER SSH 01 : 22"
"KILL 10003 : SERVER SSH 02 : 22"
"KILL 10004 : SERVER SSH 03 : 22"
"KILL 10005 : SERVER SSH 04 : 22"
)
while opt=$(zenity --width=300 --height=320 --title="KILL SSH TUNNEL" --text="Choose Tunnel" --list --column="List" "${options[@]}"); do
case "$opt" in
"${options[0]}" ) kill -9 $(ps aux | grep ssh | grep 10000: | awk '{print $2}');;
"${options[1]}" ) kill -9 $(ps aux | grep ssh | grep 10001: | awk '{print $2}');;
"${options[2]}" ) kill -9 $(ps aux | grep ssh | grep 10002: | awk '{print $2}');;
"${options[3]}" ) kill -9 $(ps aux | grep ssh | grep 10003: | awk '{print $2}');;
"${options[4]}" ) kill -9 $(ps aux | grep ssh | grep 10004: | awk '{print $2}');;
"${options[5]}" ) kill -9 $(ps aux | grep ssh | grep 10005: | awk '{print $2}');;
*) zenity --error --text="Choose again";;
esac
break
doneExplain this script
You see, this script is similar to the script to create ssh tunnel for using Zenity.

The only difference here is the command used in the options.
Here, we use the ps command and find the port we created the tunnel. From there, we find its PID and kill that PID process.
This command will grep process with service ssh and port 10000. For example, we created ssh tunnel with port 10000.
ps aux | grep ssh | grep 10000This pipe will get PID of this tunnel.
awk '{print $2}'And finally, we use kill command to kill this tunnel.
kill -9 $()Conclusion
This article is still stopping at writing script files to create a GUI for the program. In the following articles, I will guide you to add scripts to the menu for ease of use.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).