I guess, we all come across situations like, dropping your ssh remote server connection in middle of transferring file/folder, running fsck, executing a script, kernel recompilation..etc. There are many reason that you say for dropping your ssh connection. It can be an network issue, firewall issue, system corrupt…etc.
There are two ways to avoid this, nohub and another one is screen. Based on my experience, I would say nohub is useful only when you execute/run a script.
But screen has many advantages and features over nohub, so its a advisable one in a production server environment. screen allows you to run the process continuously on remote machine even after connection drops.
*) Install screen utility on your machine.
yum install screen (linux)
apt-get install (ubuntu)
*) Start screen session:
screen or screen -S <nameyoursession>
[BALAJI@devils ~]$ screen -ls
No Sockets found in /var/run/screen/S-BALAJI.
[BALAJI@devils ~]$ screen -S monitor
[detached from 3664.monitor]
*)Detach the current session:
now you are in the session, so you can run your commands there. If you want to come back to your norml SSH session, press ctrl+a to release,and then press d to detach the session.
*)To list the session already started.
# screen -ls
[BALAJI@devils ~]$ screen -ls
There is a screen on:
3664.monitor (Detached)
1 Socket in /var/run/screen/S-BALAJI.
To re-attach the session:
# screen -r <session name>
[BALAJI@devils ~]$ screen -r 3664.monitor
*)Create more sessions:
When you are already in a session, press ctrl+a, and then c to create new session. You can create n number of sessions in this way.
*) Accessing different sessions:
Press ctrl+a, and then press n(next session) or p(previous session).
*)To terminate the session:
Enter “exit” or press ctrl+d.
Thats all about screen. Let us start to have a habit of using screen session to make job easy
![]()
![]()