Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

e.g.

  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

1 Answer 1

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
    
I'll look into that. thanks :) –  mrjayviper May 20 at 0:57

Your Answer

 
discard

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.