4 ms·
That `tmux` bit is clever. Wonder if you could do that in a `ForceCommand` or something like that so you don’t need to type that part either?
by mmalone 6y ago
That `tmux` bit is clever. Wonder if you could do that in a `ForceCommand` or something like that so you don’t need to type that part either?
- mod 6y ago(Not OP) I personally don't type my advanced commands, I alias them. So I would use "ssh-target" as my alias there.
- chrisweekly 6y agoSame -- and I comment them heavily, so when (like today per this thread) I learn more about said advanced options, I'm "forced" to update my "docs". Always be capturing your knowledge! :)
- xelxebar 6y agoA combination of `RemoteCommand` and `RequestTTY` should do the trick: Host <host> ... RequestTTY yes RemoteCommand tty The problem is that this will mess up your one-off command invocations of ssh, git ssh connections, etc: $ ssh <host> ls Cannot execute command-line and remote command. However, we can use `Match` blocks to get around that! There are a thousand ways to skin this cat, but one way is to use an environment variable, here `t` for "tmux". Put this at the end of your config: Match exec "test ${t:-0} = 1" RequestTTY yes RemoteCommand tmux has-session && tmux attach-session || tmux and the following Just Work, reattaching tmux sessions as necessary: $ t=1 ssh <host> $ ssh <host> ls
- mmalone 6y agoNice. `Match exec` is one of my favorite things. It's too bad the command being passed to `ssh` (if there is one) isn't available as a `TOKEN` (as far as I can tell). That would put a bow on everything.
- pletnes 6y agoI simply have two configs for machines I ssh to often - one to the «normal shell» and one to a tmux instance with standard name.