Terminal multiplexer
Some commands take longer like copying large amount of data.
If you do not want to or can’t keep the terminal session open, there is the option to use either tmux
or screen
.
Both are terminal multiplexers with different capabilities.
The basic idea is to log into a server via ssh and start a multiplexer session there. Running ssh in a multiplexer session does not help because the transfer would also stop is you close the session or loose the connection. Having a multiplexer session on the server allows you to log out and even turn of the computer. The transfer continues because it is running on the server in the background without the need for an open connection.
In order to reconnect, make sure you are on the same server/login node that you started the session on. For more information, see the paragraph Why can’t I resume my session?.
tmux
A new tmux
session can be started with the command
tmux new -s my_session
Here the option -s my_session
is a name so you can reconnect more easily later.
If you get the message sessions should be nested with care, unset $TMUX to force
, you are already in a tmux session.
In this session you can now start commands that run for longer.
Leaving this session is called detaching and is done by pressing CTRL + b
releasing, and then pressing d
.
Now you can close the ssh connection or the terminal and the tmux session will run in the background.
Reconnecting is done by this command
tmux attach -t copy
A list of currently running sessions can be found with the command tmux ls
.
Ending a session can be done by executing the command exit
in a tmux session or by using this command
tmux kill-session -t copy
from outside of the session.
screen
Screen operates similar to tmux, when it comes to handling sessions, but the commands are a little bit different. To start a screen session named “my_session” for example, run:
screen -S my_session
Here you can run the commands you want.
Detaching from this session is done by pressing CTRL + a
, releasing and then pressing d
.
A list of running screen sessions can be shown by running screen -ls
.
Reattaching can be done with the command
screen -r my_session
If there is only one session running, just screen -r
also works, otherwise it will also show you the list of sessions.
Similarly, exiting a session can be done by using the exit
command in the session or pressing CTRL + a
, followed by k
.
Why can’t I resume my session?
In order to reconnect to your session started on a specific server, it is required that you are on the same server/login node because the sessions are running locally and are not shared between them like your directories and files. Therefore, you need to remember the server’s name.
If you are on the wrong server, or your session has ended for some reason, you’ll get messages like no sessions
, can't find session my_session
or
There is no screen to be resumed
.
As an example, you connected to a random login node using ssh glogin.hpc.gwdg.de
(technically a so called DNS-round-robin), landed on glogin6, started a tmux session and later got disconnected due to a timeout or network interruption.
When you connect to the generic DNS name “glogin.hpc.gwdg.de” again, you will likely end up on a different login node than before, i.e. glogin3 and will be unable to resume your session.
Refer to the table on the login nodes and examples page for an overview.
In order to avoid this issue, remember the hostname of the server you started the session on. For example, if your command prompt looks like this:
[u11324@glogin8 ~]$
you’re on glogin8. You can then directly ssh to the same node by running
ssh glogin8.hpc.gwdg.de
and should have no problems resuming your session.
If that still does not work, the login node may have been rebooted in the meantime, check your emails if there was an announcement. This does not happen often, but is not avoidable sometimes.