Home > bash > tmux: a screen alternative

tmux: a screen alternative

A few days ago I wrote about the awesome tool screen. Then, some of my readers namely “i90rr _” and Rodnee suggested that I should try tmux (thanks for the tip). Actually, I tried it years ago, but since I didn’t have to work with SSH too much, it was not integrated in my daily routine. However, a few days ago I bought a Digital Ocean VPS to do some Python webapp development and now I do need ssh :) And without screen / tmux it would be a pain.

So, after screen, let’s see tmux.

tmux: an advanced and friendly terminal multiplexer

The scenario is the same:

From machine A, which is your local machine, you want to SSH to a remote server.

Log in with SSH:

ssh -p PORT USER@

Specify the port if the SSH daemon is not on port 22. In the case of screen I used screen twice, but now I think it’s not necessary. First just use “ssh”. To keep the connection alive between machines A and B, it’s a good idea to use this alias:

alias ssh='ssh -o ServerAliveInterval=60'

More info about it here.

Once you are logged in to machine B, make sure that you have a recent version of tmux installed. More info here. And now just start tmux and use it :)

My config file

A big advantage of tmux over screen is its sane configation system. You can find my ~/.tmux.conf file here, I won’t copy it here.


My tmux looks like this:

In the top right corner I also display my hostname and IP address, but it’s blurred out on the screenshot.


A very special feature of screen / tmux is the ability to detach. It means that you have several tabs open within tmux (tmux calls them “windows”), and pressing “Ctrl-b d” you can close tmux. However, the programs in its tabs are still running, they are not terminated! You can close SSH, even restart your local machine, it doesn’t matter. When you log in again to machine B with SSH, you can attach to this tmux session and voilá, there you have your tabs and every program is running.

For instance, you launch a program on the server that runs for hours. Just detach, and attach a few hours later to see the result of this program. Or, you log in to a remote server from home, launch some programs, detach, shutdown your local machine, go to your workplace, log in again with SSH and attach to tmux, and you continue where you left off at home.

I don’t want to write a tmux tutorial because others have already done it much better. So let’s see some links:



I use two simple scripts to make re-attaching easier. The first one is called “tm”:

#!/usr/bin/env bash

# tm

tmux list-sessions
echo "# tmux attach -t 0"

The second one is called “tm0”:

tmux attach -t 0

If you don’t give your tmux session a name (I don’t) then your session has ID 0. When I log in again to the remote server first I run “tm” to see the running sessions. Normally I only have one session, so its ID is 0. With “tm0” I can attach to it and continue my work in tmux. Easy peasy :)

Summary: to detach, press “Ctrl-b d”, and close SSH. To continue your work, log in with SSH, check sessions with “tm”, and attach with “tm0”. Easy peasy :)

Categories: bash Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: