Manage your ssh tunnels!

Yet another kind of controlling background ssh process. Actually it can be modified to controlling any process without pid saving feature.

So, here we go: $ git clone https://github.com/theg4sh/bgctl.git $ cp bgctl/bgctl sshtunnel.sh $ chmod +x sshtunnel.sh
This trick based on environment inheritance of processes in linux, so we can declare any unique named variable to ssh process and later find it name in /proc/.

The next line appended to the end of sshtunnel.sh bgctl -p /tmp/.ssh_tunnel.pid -- ssh -f -N -R 127.0.0.1:10022:10.0.0.5:22 username@192.168.0.1
After run ./sshtunnel.sh and successful ssh authorization in /tmp folder will be created file .ssh_tunnel.pid with correct pid of forked ssh process.

In finally, to stop ssh tunnel run: $ ./sshtunnel.sh stop

All done, have a nice day.

Leave a Reply

Your email address will not be published. Required fields are marked *