Second SSH necessary? How to keep the droplet active without an active session?

Hi there, I’m new to this, but I have small basic experience with my Raspberry Pi and Debian.

What I want to reach: I want a Debian system, where I can run a Python 3.4 script, which includes an endless loop (so in the script is a “while True” condition). It makes some API calls to several websites, calculates some numbers and save the result in a .txt file and also prints some of the results. This should be done 24hours a day nonestop. Of course it should be only accessed by me, regardless where I am.

What I already did:

First Question about second SSH: But now in Step Four, there is something written about SSH again. Why? I already enabled SSH to access my droplet. Why another SSH ? My thought is: “no one except me should be able to access my droplet, so why a second security measure? The first should be save enough?” Or is there another reason for this second SSH?

Second Question: If access my droplet via Putty and start the script, it will run. But if I close Putty, I think also my script is shut down. But I want the script to run 24h a day. At my Raspberry Pi I have a desktop environment with Remote access from my PC (xrdp). I just start the terminal and start the script in it. When closing the remote access, the script is not shut down. Now I can start the remote connection from time to time, to check the prints from my script, if it is still running without problems. This is what I also want for my droplet now. The Desktop is not necessary I think (only 512 ram), but I want a way, to see the prints from the script and to check from time to time, if everything is still running.

Third Question: Is there anything else I should do? Maybe a VPN (what is a VPN?) ?

Thank You :)

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

For your first question, if you’ve already set up SSH access following the first tutorial then no need to do it again while following the second.

For your second question: Yes, closing PuTTY will stop the script if you just started it by running it directly as it logs out your user and ends it session. There are a number of ways to ensure that a long running process persists after logging out. You could use a tool like screen to keep your session open after closing PuTTY. Or you could set up your script to be run like a service.

Debian 8 uses systemd for it’s init system. To run your script as a service, you can create a systemd unit file: /etc/systemd/system/myscript.service

Description=My script

ExecStart=/usr/bin/python /path/to/


You can then start and stop your script like you would any other system service:

root@debian:~# sudo service myscript start
root@debian:~# sudo service myscript status
● myscript.service - My script
   Loaded: loaded (/etc/systemd/system/myscript.service; disabled)
   Active: active (running) since Fri 2015-10-30 13:33:31 EDT; 1s ago
 Main PID: 1220 (python)
   CGroup: /system.slice/myscript.service
           └─1220 /usr/bin/python /root/

You can find some more in-depth info on working with systemd here: