
How to Use a .env File in Python with python-dotenv (Step-by-Step Guide)
June 23, 2025
Install and Use Waymore: The Ultimate Recon Tool for Bug Bounty and Pentesting
June 25, 2025How to Use Tmux to Keep SSH Sessions Running (Even After Disconnecting)
Tmux is a terminal multiplexer that lets you manage multiple terminal sessions inside one window. More importantly: it keeps those sessions running even after you disconnect from SSH. Perfect for long jobs, remote scripts or anything you don’t want killed by a dropped connection.
🚀 Why Use Tmux?
If you’ve ever lost progress because your SSH connection dropped mid-job, you know the pain.
With Tmux you can:
- Detach from a session and reattach later (even from another device)
- Run scripts, scans or brute-forcing tools without fear of interruption
- Split your terminal into panes to multitask efficiently
🧰 What’s a Terminal Multiplexer?
A terminal multiplexer like tmux
lets you run multiple terminal sessions in one window, switch between them, and keep them alive even if your connection drops. When you SSH—a way to securely access remote servers—tmux
ensures your commands don’t die if your Wi-Fi cuts out or you close your laptop.
📦 Installing Tmux
Tmux is available on most Linux distributions and macOS.
Install it with:
- Ubuntu/Debian:
sudo apt update && sudo apt install tmux
- CentOS/RHEL:
sudo yum install tmux
- macOS:
brew install tmux
- Windows (WSL2): Use the Ubuntu/Debian command above inside WSL2 environment.
Verify installation:tmux -V
✅ Basic Workflow
Here’s the bare minimum you need to start using tmux effectively:
💡 Real-World SSH Use Case
Let’s say you SSH into your VPS and want to run a long script without worrying about disconnection:
Now detach with Ctrl + B
, then D
and close your terminal. Your script keeps running.
Later reconnect from anywhere:
🔧 Advanced Use Cases for Tmux
-
DevOps: Run a deployment script in one pane while tailing logs (
tail -f app.log
) in another. Detach, and check back later to monitor progress. -
Penetration Testing: Kick off a network scan (e.g.,
nmap -sS target
) in atmux
session, detach, and reconnect to review results without babysitting the process. -
Data Pipelines: Execute a long-running ETL job (e.g., a Python script processing large datasets) in a
tmux
session on a cloud instance, ensuring it survives SSH timeouts.
🧠 Extra Tips
tmux new -s name
— Start a session with a custom name for easy identification.Ctrl + B
,%
— Split pane vertically;Ctrl + B
,"
— Split horizontally.Ctrl + B
, arrow keys — Navigate between panes.tmux kill-session -t name
— Terminate a specific session.- Customize Tmux: Create a
~/.tmux.conf
file to tweak settings, e.g.,set -g mouse on
to enable mouse scrolling orset -g prefix C-a
to change the default prefix toCtrl + A
. - Session Sharing: Share a
tmux
session with a colleague by startingtmux
on a shared server and having them attach withtmux attach -t name
. Great for pair debugging. - Scripting Tmux: Automate workflows by scripting
tmux
commands, e.g.,tmux new-session -d -s backup 'bash backup.sh'
to run a backup script in a detached session.
🛠️ Troubleshooting Tmux
- Nested Sessions: If you’re running
tmux
inside anothertmux
session, the default prefix (Ctrl + B
) may not work as expected. To fix this, change the inner session’s prefix in~/.tmux.conf
(e.g.,set -g prefix C-a
). - Session Not Found: If
tmux attach
fails, first check if the session exists usingtmux ls
. If the server has rebooted, all sessions are lost unless you’re using a plugin liketmux-resurrect
. - Slow Response: Lag in
tmux
can be caused by mouse mode or frequent status bar updates. Disable mouse support (set -g mouse off
) or reduce the update frequency (set -g status-interval 15
) in your~/.tmux.conf
file for better performance.
📋 Common Tmux Errors Quick Reference
Error | Cause | Fix |
---|---|---|
tmux: command not found |
Tmux is not installed | Install it with sudo apt install tmux (or your OS equivalent) |
no sessions |
No active tmux sessions to attach to | Create a new session with tmux new -s name |
Prefix keys not working | Using tmux inside another tmux session | Change prefix in ~/.tmux.conf (e.g., set -g prefix C-a ) |
Mouse scroll not working | Mouse mode not enabled | Add set -g mouse on to your ~/.tmux.conf |
Laggy performance | Status updates or mouse mode | Try set -g mouse off or set -g status-interval 15 |
📎 Tmux vs Screen
Tmux is like screen on steroids (an older terminal multiplexer). It’s one of those tools you don’t realize you need until it keeps you productive mid-hack, mid-recon or mid-deploy. If you’re working over SSH and not using tmux, you’re missing out on a game-changer.
📦 Conclusion
Tmux is one of those simple tools that changes how you work with remote servers. Whether you’re hacking, developing, or managing infrastructure, it keeps your terminal sessions alive and organized. Install it, learn the basics, and thank yourself later.
Tmux is a must-have tool for anyone working with remote servers, whether you’re a developer, sysadmin, or security pro. It keeps your sessions alive, boosts productivity, and simplifies multitasking. Install it today, try the workflows above, and let us know how it transforms your SSH game!
⭐ Ready for a reliable, high-performance VPS at an unbeatable price? We host our own Kali labs on Hostinger: 4 vCPU, NVMe storage, 16 GB RAM and 16 TB bandwidth, backed by 24/7 support and a 30-day money-back guarantee. You’ll save up to 20% when you lock in a 24-month plan. Grab a Hostinger VPS using this referral link and support our content.
👉 Claim your Hostinger VPS (from only US$ 7.99/mo)