Leena Lee

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.

ActionShortcut
Detach from sessionCtrl+b then d
New windowCtrl+b then c
Next windowCtrl+b then n
Previous windowCtrl+b then p
Jump to window by numberCtrl+b then 0–9
Visual window pickerCtrl+b then w
Rename current windowCtrl+b then ,
Split pane verticallyCtrl+b then %
Split pane horizontallyCtrl+b then "
Move between panesCtrl+b then arrow keys
Close current paneCtrl+b then x
Auto-even pane sizesCtrl+b then E (capital)
Cycle pane layoutsCtrl+b then Space
Pop a pane out into its own windowCtrl+b then !
Scroll up in a paneCtrl+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 doesCommand
Start a new named sessiontmux new -s mywork
List all sessionstmux ls
Attach to a sessiontmux attach -t mywork
Attach to most recent, or create one if none existstmux attach || tmux new -s mywork
Attach using shorthandtmux a
Attach to a specific session by name/indextmux a -t mywork
Kill a sessiontmux kill-session -t mywork
Create a new window in a sessiontmux new-window -t mywork -n windowname
Rename a windowtmux rename-window -t mywork:0 newname
Send a command into a specific windowtmux send-keys -t mywork:0 "docker stats" Enter
Split a window into panestmux split-window -h -t mywork:0
Even out pane sizestmux 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

More posts