by a-dub · 4y ago · 0 comments
i just wish i could connect to remote tmux back ends and recover windows as organized locally after a network cut.
so the local tmux presents the ui and performs session management, and the remote tmux backends hold the shells to provide network cut resilience, but still rely on the local ui instance for all user interaction (so cut/paste buffers and mousing and such are preserved)
On remote host:
$ tmux -S /tmp/remote.sock
<now detach from session: prefix d>
On local host: $ ssh -L /tmp/local.sock:/tmp/remote.sock user@remote
$ tmux -S /tmp/local.sock attach
I Typed this on a phone and not validated but it looks good to me right now > sendmsg(5, {..., msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[7]}], msg_controllen=24, msg_flags=0}, 0) = 16
And then the client relays an error: > open terminal failed: not a terminalproblem is that it then doesn't work for local sessions. so you run it locally, which gives you local sessions and window management, but then all remote connections have to be via mosh -or- you mosh into the datacenter which is good for accessing infra, but leaves you having to run a separate instance for local work.
For example: SSH into server, start tmux on that system. If I am disconnected for some reason, SSH back into server, tmux attach -t 0 (or whatever ID I have) and I've recovered my session. Cut/copy/paste, mouse use, etc., are all treated as they are through any SSH session.
> the local tmux then remembers history and allows looking up commands on the remote shell, that would be huge.
I have an "outside" tmux session that can be run at either my desktop or laptop. When I start fresh, I open an outside tmux session and run a startup script. This preloads my outside session's copy buffers with named passwords from the `pass` password manager and creates windows to each of my remote sites. The shell for each of these windows is set to a script that does a simple loop of network check than attempt to ssh to the remote site. This ssh connection has an environment variable set that my remote bashrc will see. When this variable is set, my remote "inside" tmux connection is automatically recalled (or created if it doesn't exist.)
I have a script runs when I put the laptop to sleep that kills all the SSH connections cleanly, and when it wakes up again, every window reconnects to the remote machines and opens the remote tmux connections again. Everything is exactly where it was before and needs no intervention.
If the local tmux then remembers history and allows looking up commands on the remote shell, that would be huge.
Currently all my local work is saved but ssh into another machine? All that work is lost forever unless I explicitly save it.
$ ssh <hostname>
$ tmux --list-sessions
and
$ tmux --attach-session -t <session #>
?