tmux Session
A tmux session on a remote server is useful for maintaining persistent terminal sessions that can be detached and reattached later without losing the state of running processes.
An example use-case is running Craft's resave/all command, which can take potentially very long to complete.
Usage
Run the following in an SSH session on the remote server:
tmux new -A -s <session-name>
For example:
tmux new -A -s resave-all
This will create a new session called resave-all if one doesn't already exist. Once created, or it already exists, tmux will attach to that session.
You'll be able to identify that you're in a session by the (normally) green status bar at the bottom of the terminal which would show something like this:
[resave-all0:bash*
The status bar shows the session name and the currently active command being run.
Once inside the tmux session, you can run any commands as normal. For example:
./craft resave/all
Detaching from the session
To detach from a tmux session and leave it running in the background on the server, press Ctrl + b, then release both keys and then immediately press d.
Reattaching to the session
You can use the same command as above to reattach to the session:
tmux new -A -s <session-name>
The -A flag will ensure that if the session already exists, it will simply attach to it.
Closing the session
Ctrl + d exists the session, or alternatively you can type exit and press enter.