Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


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.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: