You can run processes on a remote server and disconnect your SSH session without killing those processes.

Here’s tmux in action. Imagine you’ve SSH’d into a server. You want to start a long-running process, like compiling some code or running a data analysis script.

$ ssh user@your-server.com
user@your-server.com's password:
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.11.0-1020-aws x86_64)

...

user@your-server:~$

First, you start a tmux session. If you don’t give it a name, it’ll just be session 0.

user@your-server:~$ tmux

Your terminal will look slightly different, usually with a green bar at the bottom. This is your tmux status bar.

Now, you can start your long-running process. Let’s pretend it’s a script called long_script.py.

user@your-server:~$ python long_script.py
Starting long process...

While that’s running, you want to detach from the tmux session. This is the magic part. You press Ctrl+b (that’s the default tmux prefix key) followed by d for detach.

user@your-server:~$ # Press Ctrl+b, then d
detached (from session 0)
user@your-server:~$

Notice you’re back at your regular shell prompt. The long_script.py is still running inside the tmux session, but your SSH connection is now free. You can log out.

user@your-server:~$ exit
Connection to your-server.com closed.

Later, you can log back into the server.

$ ssh user@your-server.com
user@your-server.com's password:
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.11.0-1020-aws x86_64)

...

user@your-server:~$

To get back to your running process, you need to attach to the tmux session. If you didn’t name it, it’s session 0.

user@your-server:~$ tmux attach

And voilà! You’re back in your tmux session, and your script is still running, exactly where you left it.

user@your-server:~$ python long_script.py
Starting long process...
Step 1 of 10 completed.
Step 2 of 10 completed.
...

If you had multiple tmux sessions, you could list them with tmux ls.

user@your-server:~$ tmux ls
0: 1 windows (created Mon Feb 14 10:30:00 2023) [198x43]

And attach to a named session, say my_work, using tmux attach -t my_work.

The core problem tmux solves is process persistence across terminal disconnections. Normally, when your SSH connection drops, any processes running in that terminal session are sent a SIGHUP signal and typically terminate. tmux creates a virtual terminal session on the server that lives independently of your SSH connection. When you detach, the tmux session and its processes continue running in the background. When you re-attach, you’re essentially reconnecting your terminal to that persistent tmux session.

The key commands are tmux new (or just tmux to start a new session) and tmux attach (or tmux attach -t <session_name>). Detaching is done from inside the tmux session by pressing Ctrl+b followed by d.

If you want to name your session from the start, use tmux new -s <session_name>. For example, tmux new -s my_project. Then, you’d attach using tmux attach -t my_project.

You can also split your tmux windows into panes. Inside a tmux session, press Ctrl+b then % to split vertically, or Ctrl+b then " to split horizontally. You can navigate between panes using Ctrl+b and the arrow keys. This allows you to run multiple commands or processes side-by-side within a single tmux session.

tmux isn’t just about detaching; it’s a full terminal multiplexer. You can create multiple windows within a single session (Ctrl+b then c to create a new window), switch between them (Ctrl+b then n for next, Ctrl+b then p for previous, or Ctrl+b then a number), and manage them all. This makes it incredibly powerful for organizing your work on a server.

The most surprising thing is how seamlessly tmux handles network interruptions. You can be actively typing a command, your Wi-Fi drops, you reconnect your Wi-Fi, and then re-attach to your tmux session, and it’s as if the interruption never happened. Your command line is exactly as you left it, and the processes are still running.

The next concept you’ll likely explore is session management and configuration, particularly how to customize the status bar and key bindings.

Want structured learning?

Take the full Tmux course →