Why I used tmux for a long-running SSH task

Half open laptop with command line window visible

Sometimes you just need to let a process run, and walk away, or sleep.

I recently had to perform a long-running task on a remote server over SSH. The kind of task where you start it, and then… you wait. Could be minutes, could be hours. And if your SSH connection drops, because your laptop goes to sleep, your Wi-Fi hiccups, or life just happens, the process dies with it. All that progress, gone.

That is exactly the situation where tmux earns its place in your toolkit.

tmux is a terminal multiplexer. In plain language: it keeps a session alive on the server, completely independent of your SSH connection. YLearn why tmux is the perfect tool for running long SSH tasks without worrying about dropped connections or lost progress.ou attach to it when you connect, start your task, then detach and disconnect. The session keeps running on the server, unbothered. When you reconnect, from the same machine, a different one, or even your phone, you just attach again and pick up right where you left off.

For my task, the workflow was simple:

  1. SSH into the server
  2. Start a new tmux session with tmux new -s cleanup
  3. Run the long-running command
  4. Detach from the session and close the terminal
  5. Come back later, SSH in again, reattach (tmux attach -t cleanup), and check the results.

No more anxiety about a dropped connection ruining hours of work.

If you work with remote servers regularly, tmux is one of those tools you do not realize you needed until you use it once. After that, you wonder how you managed without it.

I am only scratching the surface here of all possibilities tmux has to offer, but for this use case alone, it’s a life saver.

Photo by Ilnur

Share on Mastodon

About Marcel Bootsman

Marcel discovered the web in 1995. Since then he has paid attention to and worked with lots of technologies and founded his own WordPress oriented business nostromo.nl in 2009.

Currently Marcel is Partnerships & Community Manager EMEA at Kinsta. where he helps clients and partners grow with their business with Managed Hosting for WordPress.

You can contact Marcel on a diverse range of online platforms. Please see the Connect section on the homepage for the details.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *