In my ~/.ssh/config file I have the following option:

RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'

This automatically starts tmux and connects to an existing session if possible when connecting via ssh.

This causes sshfs to fail to connect with the error read: Connection reset by peer.

Is there a way to apply this options selectively only when connecting with ssh and not when attempting to mount a filesystem with sshfs?

Note that I still want to load the remainder of the options in that file for sshfs, since they are still relevant. Using sshfs -F /dev/null is not an option.

I could of course create two separate configuration files for ssh and sshfs, but that would require a bunch of duplication that seems unecessary.

  • In this case, you could change you RemoteCommand in tty -s && tmux has-session && exec tmux attach || exec tmux . This way the command will execute only when an interactive session is started. This will solve your example problem but it does not answer your question. – andcoz Sep 5 '18 at 13:35
  • @andcoz The tutorial that I lifted the RemoteCommand from actually specified to set RequestTTY yes as well, so I'm not sure that would help :-) – maxf130 Sep 5 '18 at 14:56

Suppose you used a different hostname when you want to use tmux eg

for sshfs :

ssh user@remotehost

but for tmux

ssh user@remotehost_tmux

and then in your ~/.ssh/config have a section specific for the host remotehost_tmux


# Global Options
#UseRoaming no

# Hostname specific options
Host <hostname>_tmux
     RemoteCommand /bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'
Hostname <hostname>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.