How do I kill a backgrounded/detached ssh session?

前端 未结 11 1258
刺人心
刺人心 2020-12-01 00:02

I am using the program synergy together with an ssh tunnel

It works, i just have to open an console an type these two commands:

ssh -f -N -L localhos         


        
11条回答
  •  天命终不由人
    2020-12-01 00:17

    Based on the very good answer of @ghoti, here is a simpler script (for testing) utilising the SSH control sockets without the need of extra configuration:

    #!/bin/bash
    if ssh -fN -MS /tmp/mysocket -L localhost:12345:otherHost:12345 otherUser@otherHost; then
        synergyc localhost
        ssh -S /tmp/mysocket -O exit otherHost
    fi
    

    synergyc will be only started if tunnel has been established successfully, which itself will be closed as soon as synergyc returns. Albeit the solution lacks proper error reporting.

提交回复
热议问题