I've got 20 or so machines scattered around the country (RPi's) and they are all on mobile networks (don't have a public IP.) Occasionally, I need to get access to a machine, so I've set up a rescue script that the machine will try to pull down every so often, and I can have that script do a reverse SSH onto my server so I can log in to it. This is working well, but I'm trying to figure out how / where I can kill that session.
Basically, I want to run the same script on all machines (they won't all run at the same time, and they pull down only their specific script anyway). So I want them to connect to my server, where I can then access them by doing something like:
ssh -p 2222 pi@localhost
But even after I connect and exit, this connection persists, which I assume will cause problems for another machine trying to connect as well. I don't want to give each machine its own port number, so I need to figure out how to kill that reverse SSH session. Not sure if it has to be done on the Pi, or on my server. Any ideas?
ps | grep <port_forwarded>
on the remote machine and then kill that PID.ps aux
or something that would list all the ssh sessions (and running processes). I'm guessing the user you log in as is different than the user that initiated the tunnel?