You need this if you're running linux servers
November 30, 2026
After I set up a Linux server and I tried to live with just SSH
But then I had to work with files that are on the server so I started using VSCode Remote SSH
But then the session kept crashing, I lost my work and I got annoyed
Finally I found a way to access my Linux server that was running Ubuntu 20.04 LTS and all my self-hosted containers with a reliable connection and stopped having problems getting disconnected.
Even when I got disconnected my work was saved.
The simple solution is the following steps:
1. Install tmux on your server
You want to install tmux on your linux server, not your laptop
# Ubuntu/Debian
sudo apt update && sudo apt install tmux
Check that it installed correctly:
tmux -V
# should print something like "tmux 3.3a"
2. SSH into your server like normal
ssh your-username@your-server-ip
3. Start a tmux session
tmux new -s mywork
The -s mywork names the session, which matters once you have more than one running.
4. Do your thing
Run whatever you'd normally run: a script, a server, an install. It's just a regular terminal at this point.
5. Detach (don't close your terminal, detach instead)
Ctrl+b, then d
This is the key habit change. Instead of closing the terminal window when you're done for now, you detach. The session keeps running on the server even after you close your laptop or your SSH connection times out.
6. Reconnect later, from anywhere
ssh your-username@your-server-ip
tmux attach -t mywork
Everything is exactly where you left it. Same scrollback, same running processes.
7. If you forget the session name
tmux ls
This lists every active session so you can attach to the right one.
Turning it into a script
I have AI agents running on docker containers and I want to easily access the containers without having to remember all the commands so I wrote a script
Now every time I need to set things up on a new computer, I just run the script and my sessions and AI agents can be up and running in minutes.
Here's the layout I landed on for my AI agents:
Session: agents
├── Window 0 "shell" → plain bash
├── Window 1 "agent-1" → docker exec -it agent-1 bash
├── Window 2 "agent-2" → docker exec -it agent-2 bash
├── Window 3 "agent-3" → docker exec -it agent-3 bash
└── Window 4 "logs" → docker logs, one pane per agent
1. Create the script file
mkdir -p ~/scripts
vim ~/scripts/start-agents.sh
2. My script for your reference
Don't just copy and paste this in, you'll have to think about how you want to set things up yourself.
#!/bin/bash
# Kill existing session if it exists, so we always start clean
tmux kill-session -t agents 2>/dev/null
# Window 0: plain shell
tmux new-session -d -s agents -n shell
# Window 1-3: one per agent
tmux new-window -t agents -n agent-1
tmux send-keys -t agents:agent-1 "docker exec -it agent-1 bash" Enter
tmux new-window -t agents -n agent-2
tmux send-keys -t agents:agent-2 "docker exec -it agent-2 bash" Enter
tmux new-window -t agents -n agent-3
tmux send-keys -t agents:agent-3 "docker exec -it agent-3 bash" Enter
# Window 4: logs, split into 3 panes
tmux new-window -t agents -n logs
tmux send-keys -t agents:logs "docker logs -f agent-1" Enter
tmux split-window -h -t agents:logs
tmux send-keys -t agents:logs "docker logs -f agent-2" Enter
tmux split-window -h -t agents:logs
tmux send-keys -t agents:logs "docker logs -f agent-3" Enter
tmux select-layout -t agents:logs even-horizontal
# Land back on the shell window
tmux select-window -t agents:shell
# Attach
tmux attach -t agents
3. Make it executable
chmod +x ~/scripts/start-agents.sh
4. Run it
~/scripts/start-agents.sh
Keyboard shortcuts I actually use
tmux shortcuts all start with a "prefix" (by default Ctrl+b). You press that, release it, then press the next key.
| Action | Shortcut |
|---|---|
| Detach from session | Ctrl+b then d |
| New window | Ctrl+b then c |
| Next window | Ctrl+b then n |
| Previous window | Ctrl+b then p |
| Jump to window by number | Ctrl+b then 0–9 |
| Visual window picker | Ctrl+b then w |
| Rename current window | Ctrl+b then , |
| Split pane vertically | Ctrl+b then % |
| Split pane horizontally | Ctrl+b then " |
| Move between panes | Ctrl+b then arrow keys |
| Close current pane | Ctrl+b then x |
| Auto-even pane sizes | Ctrl+b then E (capital) |
| Cycle pane layouts | Ctrl+b then Space |
| Pop a pane out into its own window | Ctrl+b then ! |
| Scroll up in a pane | Ctrl+b then [ (use arrow keys, q to exit) |
Commands I actually use
These work from a plain terminal (not inside tmux) unless noted:
| What it does | Command |
|---|---|
| Start a new named session | tmux new -s mywork |
| List all sessions | tmux ls |
| Attach to a session | tmux attach -t mywork |
| Attach to most recent, or create one if none exists | tmux attach || tmux new -s mywork |
| Attach using shorthand | tmux a |
| Attach to a specific session by name/index | tmux a -t mywork |
| Kill a session | tmux kill-session -t mywork |
| Create a new window in a session | tmux new-window -t mywork -n windowname |
| Rename a window | tmux rename-window -t mywork:0 newname |
| Send a command into a specific window | tmux send-keys -t mywork:0 "docker stats" Enter |
| Split a window into panes | tmux split-window -h -t mywork:0 |
| Even out pane sizes | tmux select-layout -t mywork:0 even-horizontal |
| Switch sessions (from inside tmux) | tmux switch-client -t mywork |
One gotcha worth knowing: if you're already inside a tmux session and try to run tmux again, you'll get a warning about nesting sessions. Use tmux switch-client instead of tmux attach when you're already inside tmux: attach is meant to be run from a plain shell.
This is almost life changing
Finding out and using tmux was like having to carry around your keys to installing a keypad on your front door.
It's not a crazy big change but it's still life changing.
I stopped losing work to idle timeouts.
And I stopped worry about getting disconnected.
If you're running anything long-lived on a remote linux server, tmux definitely a must have
Want the next build?
New videos go up on YouTube first.
Keep reading
Self-Hosting & Homelab
If you don't want big tech to have all of your data, read this
How I turned an old desktop into a self-hosted photo and video server with Immich, so Google and Apple don't have access to all of it.
November 30, 2026