A Guide to Screen and Tmux
When working with remote servers or running long-running tasks, keeping your
terminal sessions active and organized can be a challenge. Tools like
screen
and tmux
help you manage multiple terminal sessions, detach
and reattach to running processes, and organize your workspace with ease.
In this guide, we’ll explore what screen
and tmux
are, explain their core
features, and show you how to use them to make your remote work more efficient
and resilient. By the end, you'll be able to keep your workflows running
uninterrupted, even when you disconnect from the terminal.
tmux
has a lot of configuration that can really help it become a great
productivity tool. I use it on all my terminals and I have multiple plugins to
make it even more powerful!
Why Use screen or tmux?
Without screen
or tmux
, if you disconnect from your SSH session, any running
commands or processes will terminate, potentially interrupting important tasks.
These tools allow you to detach from sessions and leave processes running in
the background. When you reconnect, you can simply reattach to your existing
sessions and pick up right where you left off.
Screen — The Basic Terminal Multiplexer
screen
is a utility that provides the ability to run multiple shell sessions
within a single SSH connection. It’s simpler than tmux
, making it a good
starting point if you’re new to terminal multiplexers.
Basic screen Commands
- Starting a New Screen Session
This creates a new screen session and opens a shell prompt within it. Once
inside, you can run commands as usual.
- Detaching from a Screen Session
Press Ctrl + a
followed by d
. This detaches you from the screen session,
leaving the processes inside running in the background.
- Listing Screen Sessions
This shows a list of active screen sessions and their IDs.
- Reattaching to a Screen Session
Use the session ID from the screen -ls
output to reattach to a running
session. If only one session exists, you can simply run screen -r
without the
ID.
- Creating a Named Screen Session
If you often have multiple sessions, it’s helpful to name them:
Replace <session-name>
with something descriptive, like project-build
. This
makes it easier to identify and reconnect to specific sessions later.
- Killing a Screen Session
To terminate a screen session:
screen -X -S <session-name> quit
This command forcefully ends the session specified by its name or ID.
Useful Screen Shortcuts
Ctrl + a, c
: Create a new window within the screen session.
Ctrl + a, n
: Switch to the next window.
Ctrl + a, p
: Switch to the previous window.
Ctrl + a, "
: List all windows.
Practical Example: Using Screen for Long-Running Scripts
Suppose you want to run a long data processing script on a remote server, but
you don’t want it to terminate if your SSH session drops:
- Start a screen session:
screen -S data-processing
- Run your command:
-
Detach from the session using Ctrl + a, d
.
-
Later, if you want to check on the process, reattach using:
screen -r data-processing
This way, your script keeps running even if you disconnect from the server.
Tmux — The Modern Terminal Multiplexer
tmux
is a more feature-rich alternative to screen
with additional
capabilities for window management, session management, and scripting. It allows
you to create multiple terminal windows within a single session, split panes
within windows, and even synchronize inputs across multiple panes.
Basic tmux Commands
- Starting a New Tmux Session
This starts a new session. You’ll see a status bar at the bottom indicating
you’re inside a tmux session.
- Creating a Named Tmux Session
tmux new -s <session-name>
Replace <session-name>
with something meaningful, like development
. This is
useful for managing multiple sessions.
- Detaching from a Tmux Session
Press Ctrl + b
followed by d
. This detaches from the current tmux session,
leaving processes running in the background.
- Listing Tmux Sessions
This command lists all active tmux sessions.
- Reattaching to a Tmux Session
tmux attach -t <session-name>
Use the session name to reattach to a specific tmux session. If only one session
is running, you can omit the -t <session-name>
part.
- Killing a Tmux Session
tmux kill-session -t <session-name>
This command terminates a session by name.
Tmux Window and Pane Management
Unlike screen
, tmux
allows you to split your terminal into multiple panes,
making it perfect for multitasking.
-
Creating a New Window: Ctrl + b, c
-
Splitting Horizontally: Ctrl + b, "
(Splits the current window into two horizontal panes)
-
Splitting Vertically: Ctrl + b, %
(Splits the current window into two vertical panes)
-
Navigating Between Panes: Ctrl + b
followed by an arrow key
-
Resizing Panes: Ctrl + b
followed by :
and then use the commands like
resize-pane -L 10
to resize left by 10 units.
Example: Organizing Your Workflow with Tmux
Let’s say you’re working on a web development project. You can set up a tmux
session with separate windows for editing code, running a web server, and
monitoring logs:
- Start a new session:
- Create multiple windows:
- Use
Ctrl + b, c
to create a window for editing code (vim
or nano
).
- Create another window (
Ctrl + b, c
) to start your server (python manage.py runserver
).
- Create a third window to monitor logs (
tail -f /var/log/server.log
).
- Switch between windows:
- Use
Ctrl + b, n
for the next window.
- Use
Ctrl + b, p
for the previous window.
Sharing and Collaboration with Tmux
One powerful feature of tmux
is its ability to share sessions. If you’re
collaborating with someone remotely, you can both attach to the same tmux
session and see each other’s inputs.
- Create a shared tmux session:
- Have another user on the same server attach to the session:
Now, both users can type and see each other’s actions, making it perfect for
pair programming or troubleshooting.
Decking Out Tmux
If you'd like a fully decked out tmux with colors, icons, and custom keybinds,
then you can watch this video where Dreams Of Code goes over his tmux
configuration: Dreams Of Code |
YouTube.
You'll get sometime like this as a result:


Choosing Between screen
and tmux
-
Use screen
if you need a simple tool for keeping terminal sessions
active and have no need for complex layouts or scripting.
-
Use tmux
if you want advanced features like split panes, window
management, and session sharing.
Summary
Both screen
and tmux
are powerful tools for managing terminal sessions, but
tmux
offers more flexibility and features. Knowing how to use these tools will
help you maintain long-running processes, organize your terminal windows, and
enhance your productivity on remote systems.
screen
: Easy to use, good for beginners, simple session management.
tmux
: Feature-rich, supports panes and windows, ideal for complex workflows.
With these tools, you can now work confidently on remote systems, never losing
your place or disrupting your workflows!