How To Manage Multiple Screen Sessions

Start, Run, And Detach All Screen Sessions At Once

Billy Bonaros


Photo by NordWood Themes on Unsplash

Linux’s Screen lets you run terminal applications to a Server in the background even if you disconnect from the ssh connection. It’s especially useful for us when running APIs or Web Apps like Streamlit.

The problem with Screen is that if the server goes down for any reason like update, restart, etc. you have to run all the screen sessions manually one by one. A great solution for it is to create an executable file and add all the screen sessions there.

The Executable

Firstly we need to create a “sh” file having in its first line the following.


Then, we need to add the screen session commands.

The screen command has to do the following:

  1. Start a Screen Session
  2. Activate the App/API Environment(if any)
  3. Navigate to App/API’s path
  4. Run the App/API
  5. Detach the Screen Session

To achieve all these 5 steps, we can run the following:

screen -dmS app_name bash -c 'cd /path_to_app; /home/conda/envs/custom_env/bin/python /path_to_app/'