First off, what do I mean by a persistent session? I want to be able to log into a remote machine, do some stuff, and log out without losing my running processes. Later, I should be able to log back in and pick up exactly where I left off. As an example, I am constantly running long simulations on the machine in my lab. I would like to be able to tunnel into my lab from home, start a simulation, and log out without interrupting the simulation. After a couple of hours, I should be able to log in again and check on the progress of the simulation. Simple enough, right?
Tmux allows you to do this by detaching a session. The important thing to remember is that the session lives on the remote machine. Therefore tmux must be installed (and running) on the remote machine. The tmux server takes care of processes that you started and `returns` them to you when you reattach.
So, in a few simple steps:
Log into your remote machine,
dkudrow@local_machine:~$ ssh dkudrow@remote_machine
Create a tmux session on the remote machine,
dkudrow@remote_machine:~$ tmux
After starting your simulation or doing some work, detach the tmux session. In the tmux command line enter,
:detach
No you can log out of the remote machine without interrupting the session,
dkudrow@remote_machine:~$ logout
To resume the session, log back into the remote machine and enter,
dkudrow@remote_machine:~$ tmux attach
And voila, just as you left it.
This is just a basic example. Things get more complicated with multiple sessions across multiple machines but hopefully this gets you started.
No comments:
Post a Comment