https://github.com/crigler/dtach is a wonderful tool that not enough people know about. It is for detaching a program from its controlling terminal, so that you can connect/disconnect remotely while it is running. This is particularly useful when combined with ssh or mosh.
You can do this with screen or tmux, but dtach is simple and free of baggage. In particular it does not consume useful keybindings like control-A, so it won't get in your way when using emacs. Its main feature is the detach keybinding, control-\\ by default. Here's how I use it:
```shell
alias foossh='ssh -t foohost'
alias foosh='mosh -n -- foohost'
alias fooemacs='foosh dtach -A .dtach.emacs -z emacs -nw'
```
foossh or foosh starts or resumes a remote shell session at foohost. fooemacs does the same for a terminal emacs, saving the connection's state in `~/.dtach.emacs` on the server. Now you have a long-running terminal emacs, with all of its windows, frames, processes, and history, which you can connect to with `fooemacs` and disconnect from with `C-\` - terrific for sysadmin, eg.