What is screen
screen is a free software terminal multiplexer developed by the GNU Project.
It has many features, but here I’ll focus on one particularly useful for remote server management:
Session Recovery
When you connect to a remote server and start a terminal session with screen, as long as screen itself hasn’t terminated, all sessions running inside it can be recovered. This effectively solves issues like session hang/disconnection caused by network problems when remotely managing Linux servers.
Usage
After installation on the remote server, run the following command to create a session named sessionName:
screen -S sessionNameCommon screen parameters:
screen -S sessionName -> Create a new session named sessionNamescreen -ls -> List all current sessionsscreen -r sessionName -> Reattach to the session named sessionNamescreen -d sessionName -> Remote detach a sessionscreen -d -r sessionName -> End current session and reattach to sessionNameSession Status: Attached
When you detach from screen and later try to reconnect, sometimes the screen session status remains “Attached” and you simply can’t reconnect.
List the session ID with Attached status:
screen -lsscreen -D -r <session-id>Note: -D -r forcefully kicks out the previous user, then logs in.
More
Official site: https://www.gnu.org/software/screen/