Automatic kill of user gust connection, via ssh
-
In former page I suggested a nice way to connect the office machine to home, via ssh.
Remote Connecting To Work Computer - main page.
-
The remote connect script, which runs on the office machines, knows how to reconnect. However when IP changes, I need sometime to manually kill the connection, from the machine at home. This in turn triggers the script at work to re-connect.
-
The office machine uses a reduced permission user account for guests. To kill the connection, I need to be either super user or enter the guest user.
Since I usually don't remember the gust password, I do it as super user. I use a script to automate the process and avoid stupid mistakes.
Note: that although the script is run from the super user, it kills only process of a specific user.
#!/bin/bash
#guestA 28530 28511 0 13:34 ? 00:00:00 sshd: guestA@pts/8
#guestA 28515 28513 0 13:34 ? 00:00:00 sshd: guestA@pts/5
for f in $(ps -aefH | grep "^guestA.*ssh" | sed 's/guestA *\([0-9]*\) *\([0-9]*\).*/\1/'); do
cmd="kill "$f
echo $cmd
$cmd
done
|