Using a Screen
When running commands that affect the system through SSH, we run the risk of our commands getting cut short mid-process if a connection is lost. This is becomes more important when running commands that take a long time to complete such as software builds. We can use the unix tool screen to create a persistent session. This way, if you lose your connection, the build and install will still continue to run on the server.
First, we must create a screen. When we do, your terminal will “enter” the screen. Each screen must have a name. You can use any name but for this example the name is “mybuild”.
To create a screen, run:
screen -S mybuild
Now you can run commands inside the screen. Once we are finished with the screen, we can exit it like any shell with the exit command or by hitting Ctrl + D.
We can gracefully disconnect from the screen and allow it to keep running on the server. To do this, press Ctrl + A followed by D.
After we have either lost connection or gracefully disconnected from a screen we can re-enter the screen. If there is more than one screen running on the server, we need to know the name of the screen first. To list the screen names, run this command:
screen -ls
When it prints the list, there will be a numerical prefix to a screen name. When we reconnect, we can specify the name, the number in the prefix or the prefix with the name. Here is the format for that command:
screen -r myscreen\