Skills: persistent remote session

It is convenient to be able to keep a shell running on a login node, perhaps because you have a long-running process, or you are on an unreliable internet connection.

There are two tools which can help: screen and the more modern tmux.

Normally, when logging in to an Eddie login node, you ssh to eddie.ecdf.ed.ac.uk. This is actually an alias, and you will be allocated to one of the actual login nodes, such as login01 or login02. This isn’t a problem, until you want to reconnect to the same machine.

Fortunately, the solution is simple: we will connect a specific login node using its special external name: login01-ext.ecdf.ed.ac.uk or login02-ext.ecdf.ed.ac.uk. Pick one now, and stick with that for the rest of the assignment.

You need to add an entry to ~/.ssh/config in order to login without a password. This will be similar to the existing entry for eddie.ecdf.ed.ac.uk, and can use the same .ssh key (you don’t need to generate a new one). Alternatively, edit your existing entry for eddie, replacing eddie.ecdf.ed.ac.uk with login01-ext.ecdf.ed.ac.uk or login02-ext.ecdf.ed.ac.uk

Let’s first learn how to use tmux in a terminal. Launch a terminal, ssh to your chosen login node, and start tmux:

ssh login01
tmux
echo "Hello World"

Practice detaching by typing ctrl-b d and reattaching by running tmux attach. Then make sure you can do the following:

  1. start a terminal
  2. ssh to a login node
  3. start tmux
  4. do something in that shell
  5. detach from tmux
  6. logout of the login node
  7. close the terminal

Then, some time later:

  1. start a terminal (could even be on a different computer)
  2. ssh to the same login node
  3. reattach to tmux
  4. continue whatever you were doing in step 4

If this is all new to you, it might be a little mind-bending at first, but keep practicing until it feels familiar and comfortable. Once it does, you can explore the more advances features of tmux by finding an online tutorial such as this one.

Let’s pause for a moment to ask “Why are we doing all of this?”

The answer is: so we can work more efficiently on a remote computer.