As a bioinformatician, I've always been ssh-ing into clusters/remote machine at schools or work for most of my daily work. This works great for me because most of the bioinformatics dataset are at least in the gigabyte range and I don't want them sitting on my local machines eating my storage. On top of that, working on remote machines ensures that (1) I can pick up the work by logging in from virtually any laptop, so I don't need to be very attched to a single laptop and also consequently I don't need a very powerful laptop, and (2) it's easier to share data with collaborators.
However, some pain points from my early career was that:
- if I was working with unstable internet, I could lose my work when I was working on something and the connection suddenly drops.
- if I was working with some script in a Vim window and wanted to check the path in another window, I'll need to open another ssh tab/window, the number of ssh connections can exponentially increase if I was working with a few projects at a time.
- (1) happens when I was in the (2) situation....
These had been annoying until I found that Tmux solves all these problem! Tmux stands for terminal multiplexer, meaning with one ssh connection, I can open a few shell sessions (like tabs). Secondly, I can also attach and detach a tmux session everytime I ssh into a machine, such that I don't have to worry about bad internet connections anymore because I know that my work are always saved in the tmux sessions.
my usual workflow
My usual workflow is like:
> ssh user@some_server
> tmux new -s tmux_session_name
...do some work...
at this point, the terminal window can be closed and we can ssh back in and re-attach the session:
> ssh user@some_server
> tmux a -t tmux_session_name
if you aren't sure what sessions you have opened, you can do:
> tmux list-sessions
jupyter: 1 windows (created Sat Oct 1 08:32:37 2022)
sc: 5 windows (created Fri Sep 30 18:55:00 2022) (attached)
Everything should still be there. My setup can be found in [here], which I usually re-map caps-lock to ctrl, so that I can do the following easily (with prefix-key ctrl-a
):
ctrl-a-t
: open a new tabctrl-a-d
: detach the tmux session, then you can attach another tmux sessionctrl-a-s
: split pane in half hozizontallyctrl-a-i
: split pane in half verticallyctrl-a-j
: split pane in half verticallyctrl-a-w
: close a pane
remapping key in osx
zellij is also an interesting project that could potentially replace tmux!