I want to run a python script that goes on infinitely, but it stops after I have closed the ssh terminal. I would also like to see the output from the script when I log in again.

  • You can use tmux to create a session that will continue to run even after you disconnect and can reattach later even from a different computer. As for the length of the output have you considered writing it to a combination of logfile and regular files. Jul 19, 2017 at 0:40

3 Answers 3


There are several options to solve this. You could setup your Python script as a service. A pretty good tutorial can be found here.

Another option is to have the script simply launch on startup. A good tutorial to follow can be found here.

As for the output, I would suggest that you create a file and write your output to that file.


You can use nohup command


nohup yourCommand &

after that you can quit ssh and when you go in again, you can find the file nohup.out that contains the output.

take a look here

  • Hi, I tried this but when I open nohup.out it doesn't respond- likely because there is a lot of output. Is there any other way around the problem?
    – Luke
    Jul 18, 2017 at 13:54
  • if there is a lot of output, this is the output you have on your python script, you can try to reduce this output if it is useless Jul 18, 2017 at 13:56

What you're looking for is either screen or tmux (I prefer the latter). These create a detachable console that you can then leave and then reattach to later.

Not the answer you're looking for? Browse other questions tagged or ask your own question.