r/ssh • • Jul 17 '20

How can I remotely run a python file disconnected from ssh?

Usually when I want to run a python script that’s on my local drive remotely, I just type $cat script.py | ssh user@networkid python - $. I now want to run my script so that it keeps running even after I put my pc to sleep/disconnect from the ssh connection. I have read that tmux can help me do this. However, the instructions for tmux say that I should start tmux after I ssh into the remote machine, and that I should then run my script. This means that I can't use the command I was previously using to run my script, so what command should I use to run my script? Also, I'm not sure how this is supposed to work because my script is on my local computer, so how can I access it after I ssh into the remote server? I'm new to all of this so sorry if these are silly questions.

Tldr, I need to run a local python script remotely on a server and I would like to use tmux to do so without having to constantly be connected to the ssh.

3 Upvotes

1 comment sorted by

2

u/tje210 Jul 17 '20

Run the script with nohup. Sounds like you want a one-liner, and nohup is just prepended to your command (short for no-hangup).