Working with tmux session

Tmux is a terminal multiplexer for Unix-based operating systems that enables multiple terminal sessions within a single window. It is particularly valuable when working with cloud-based services like AWS or Azure, allowing users to create separate terminal sessions for different tasks or remote users while maintaining persistent connections.

When working with web services, you often need to create an EC2 instance on a web server and establish a session to work remotely. Tmux ensures that your work continues even if your connection drops, as sessions remain active on the server.

Getting Started with AWS EC2

Here are the steps to work with tmux on a UNIX (Ubuntu) web server:

Step 1 − Setup Connection

Obtain the IP address of your AWS console and download the key file (.pem) from the console. These credentials are typically provided by your vendor or company.

Step 2 − Connect to Server

Navigate to the key file directory, right-click and open Git Bash (or terminal). Enter your server's IP address using the SSH command:

ssh ubuntu@IP_address -i keyfile.pem

Step 3 − Create Tmux Session

Once connected, create a new tmux session with a descriptive name:

tmux new-session -s sessionName

To detach from the session (leave it running in background), press Ctrl+b, then press d.

Essential Tmux Commands

Command Description
tmux ls List all active sessions
tmux attach -t sessionName Reattach to an existing session
tmux kill-session -t sessionName Terminate a specific session
tmux kill-server Kill all sessions and tmux server

Key Shortcuts

Within a tmux session, use these keyboard shortcuts (prefix with Ctrl+b):

  • Ctrl+b, d − Detach from current session

  • Ctrl+b, c − Create new window within session

  • Ctrl+b, n − Switch to next window

  • Ctrl+b, % − Split window vertically

  • Ctrl+b, " − Split window horizontally

Common Use Cases

  • Long-running processes − Keep scripts or applications running even after disconnecting

  • Multiple environments − Separate development, testing, and production work

  • Collaboration − Share terminal sessions with team members

  • Server administration − Manage multiple server tasks simultaneously

Conclusion

Tmux is an essential tool for remote server management, providing session persistence and multiple terminal capabilities. It ensures your work remains intact even during network interruptions, making it invaluable for cloud-based development and system administration tasks.

Updated on: 2026-03-17T09:01:38+05:30

477 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements