Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to automatically start a new tmux session IF there are none available when I sudo to root.


  1. reboot PC
  2. login as normal user via ssh
  3. sudo -s (which would then automatically create a new tmux session)
  4. I open another terminal/putty windows and login repeat 2 and 3 BUT this time, no session will be created as there's already one.

Any ideas how this can be done?

Thanks very much :)

share|improve this question
up vote 3 down vote accepted

Byobu makes it easy to enable and disable automatic tmux sessions on login. If you are willing to install and use byobu Install byobu as an interface to tmux to address this need, it makes it extremely simple to do what you are asking. In a terminal, run

sudo apt-get install byobu
sudo byobu-enable
sudo -i

From now on, when the root user logs in via the console, SSH, or with sudo -i, byobu will attach to an existing tmux session or create a new one if one is not already running.

Note that I use sudo -i instead of sudo -s. The -s option only starts a shell, not a login shell. You should use sudo -i to emulate a full login, which also loads roots ~/.profile, and this is where byobu will install itself when you run byobu-enable.

There are probably ways to do what you want with tmux alone, but byobu makes setting up and starting tmux automatically very simple.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.