When using tmux sessions that are invoked as part of the shell instantiation, a new session will be created each time a user SSHes into a system. When detached (as in session timeout), the sessions persists; however, when connecting back in, a new session will still be created instead of attaching to the previous session. What's the expected way to reconnect to or manage previous sessions?
In the RHEL 8 STIG, there is a finding that requires that "session control is automatically started at shell initialization". The way this is done in the STIG is by starting tmux at login. Additionally, there are other controls that cause a tmux session to lock after activity, and for ssh to disconnect after inactivity. On my STIGed system where I'm causally testing aside my main development system, I end up with a lot of idle timeouts, and therefore a lot of detached sessions.
Example of timed-out sessions
[user@system ~]$ tmux list-sessions 0: 1 windows (created Tue Jun 15 14:09:29 2021) [202x47] 1: 1 windows (created Tue Jun 15 14:32:53 2021) [202x47] 10: 1 windows (created Wed Jun 16 10:34:15 2021) [202x47] 11: 1 windows (created Wed Jun 16 10:50:04 2021) [202x47] (attached) 3: 1 windows (created Tue Jun 15 15:11:01 2021) [202x47] 4: 1 windows (created Tue Jun 15 16:47:34 2021) [202x47] 5: 1 windows (created Tue Jun 15 16:50:10 2021) [80x24] 6: 1 windows (created Tue Jun 15 18:22:36 2021) [202x47] 7: 1 windows (created Wed Jun 16 09:41:14 2021) [202x47] 8: 1 windows (created Wed Jun 16 09:52:56 2021) [202x47] 9: 1 windows (created Wed Jun 16 10:14:31 2021) [202x47]
How I've been dealing with it
If I try to reconnect to one of those, I get a warning:
[user@system ~]$ tmux attach-session -t 0 sessions should be nested with care, unset $TMUX to force
If I unset the value and attach the session again, now I have nested sessions, which greatly complicates things. In theory, i can finish up what I was working on within this nested session, but it seems like there should be a better way. What if before finishing up I detach again, then have to reconnect to the prior session, and now I'm three sessions deep?
Note: I am using this system for testing and familiarizing myself with an environment that has implemented the RHEL 8 STIG. Hopefully, on a production system, the users are more mindful of the environment and there is a reduced chance of session idle timeouts. I can disable the timeouts for my use case, but I am trying to stay to the letter of the STIG.