Published on

Never Lose Your Work Again - Using tmux on Remote Servers

Authors
tmux with long-runing task via ssh

Working on a remote server over an SSH connection is convenient, but one major downside is that if your local internet connection drops, all of the programs and processes you were running on the remote server get killed. This can lead to lost work and wasted time.

Thankfully, there's an easy solution to this problem - tmux! Tmux is a terminal multiplexer that allows you to create separate sessions and windows inside a single terminal window. This means you can run all of your programs inside a tmux session, and even if your local SSH connection drops, the tmux session (and all programs inside it) will keep running on the remote server.

Here's how to use tmux to protect your remote work:

  1. SSH into your remote server as normal.

  2. Start a new tmux session by typing:

tmux
  1. You'll now be inside a tmux session. Go ahead and start running whatever programs or processes you need inside this session.

  2. If you need to disconnect from the server (or if your connection drops), just close the SSH window. Your tmux session and everything inside it will keep running.

  3. To re-attach to your tmux session later, SSH into the server again and type:

tmux a

This will re-attach you to the same tmux session with all of your programs still running exactly as you left them!

Tmux has many more advanced features, so for a full list you can check out the getting started guide at https://github.com/tmux/tmux/wiki/Getting-Started or view the man pages by running

man tmux

on your system. But simply using it as a persistent session container is an easy way to prevent losing work on remote servers. Give it a try next time you need to run some long-running tasks!