Here is a step-by-step guide on how to run a long-running process using the screen command via SSH:
-
SSH into your server
Open your terminal and SSH into your server using the following command:
ssh username@your_server_ipReplace
usernamewith your actual username andyour_server_ipwith the IP address of your server. -
Install the Screen utility
If the
screenutility is not installed on your server, you can install it using the following command:For Ubuntu/Debian:
sudo apt-get install screenFor CentOS:
sudo yum install screen -
Start a new Screen session
You can start a new
screensession using the following command:screen -S session_nameReplace
session_namewith a name for your session. This will be useful for identifying the session later. -
Run your Python script
Now, you can run your Python script using the following command:
python your_script.pyReplace
your_script.pywith the name of your Python script. -
Detach from the Screen session
You can detach from the
screensession and let your script run in the background using the following key combination:Ctrl + A, then press DThis will detach your
screensession but will keep your script running in the background. -
Reattach to the Screen session
You can reattach to your
screensession to check the progress of your script using the following command:screen -r session_nameReplace
session_namewith the name of your session.
This way, even if your SSH session gets disconnected, your script will keep running in the screen session. You can always reattach to the screen session to check the progress of your script.

Leave a Reply