0

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?

thpetrus
  • 57
  • 1
  • 1
  • 10

3 Answers3

1

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

fuero
  • 9,413
  • 1
  • 35
  • 40
1

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.

Lungang Fang
  • 181
  • 3
0

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.

vgoff
  • 408
  • 7
  • 19