Re:SSH hacks – a little sanity for remote workers
by mmalone on Wednesday April 29, 2020 @08:59PM
(#23026393)
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?
[ Parent
| on HN ]
Re:SSH hacks – a little sanity for remote workers
by xelxebar on Wednesday April 29, 2020 @11:18PM
(#23027097)
A 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
Re:SSH hacks – a little sanity for remote workers
by mmalone on Wednesday April 29, 2020 @11:41PM
(#23027192)
Nice. `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.
Re:SSH hacks – a little sanity for remote workers
by pletnes on Friday May 01, 2020 @03:15AM
(#23039764)
I simply have two configs for machines I ssh to often - one to the «normal shell» and one to a tmux instance with standard name.
Re:SSH hacks – a little sanity for remote workers
by mod on Wednesday April 29, 2020 @09:15PM
(#23026488)
(Not OP) I personally don't type my advanced commands, I alias them. So I would use "ssh-target" as my alias there.
Re:SSH hacks – a little sanity for remote workers
by chrisweekly on Thursday April 30, 2020 @06:25AM
(#23029343)
Same -- 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! :)