Open socket server with ssh

40 views Asked by At

I can open a remote socket server to run in background with this terminal command:

ssh -p22 [email protected] nohup python3 /home/pi/scripts/sock_serv.py &

I want to open the server from the client with python like this:

import subprocess

def check_ssh():
    cmd = ["ssh", "-p22", "[email protected]", "nohup", "python3", "/home/pi/scripts/sock_serv.py", "&"]
    result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
    print(result)

check_ssh()

My problem is the server opens and runs but the above script on the client stays open. I used "nohup" and "&" to have it run in the background but the above script still stays open as long as the socket server is running.

0

There are 0 answers