I want to automatically start a new tmux session IF there are none available when I sudo to root.
e.g.
- reboot PC
- login as normal user via ssh
- sudo -s (which would then automatically create a new tmux session)
- 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 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