Friday, November 11, 2016

How can I start automatically start a tmux session on login?




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 :)



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.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...