I'm running tmux on my servers and when configuring things I like to just su into root and take care of things. Is there a possibilty to log out root automatically after I detach the tmux session?
3 Answers
There's TMOUT
:
TMOUT If set to a value greater than zero, TMOUT is treated as the default timeout for the read builtin. The select command terminates if input does not arrive after TMOUT seconds when input is
coming from a terminal. In an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. Bash terminates after waiting for
that number of seconds if input does not arrive.
You could set this in /etc/profile
if the EUID is root.
The problem with this is that it requires a compatible shell.
An alternative would be Timeoutd, but I don't know where it's available (debian-based seems to have it, rhel-based doesn't).

- 9,591
- 1
- 35
- 40
-
Thanks, I know TMOUT, is there another way to do this? Something that triggers on detach? – thpetrus Feb 08 '13 at 13:42
-
@thpetrus I mentioned timeoutd as an alternative. – fuero Feb 08 '13 at 13:46
-
Yes, but it's basically the same as TMOUT and doesn't trigger on detach. – thpetrus Feb 08 '13 at 16:57
sudo tmux attach
connects you to an existing tmux session run by the root user. Once you detach the tmux session, the sudo
command is done and you are back to the normal user.
Similarly, you can use sudo bash
to get a root shell.

- 191
- 3
TMUX is designed to survive unintentional and intentional disconnects, as you already are aware.
You could have a bash_logout
file that kills the server with the kill-server
command. This would not be internal to tmux, obviously, but would have the desired effect.
Alternatively, have it use kill-session
specifically.

- 418
- 7
- 19