I start an SSH session with a shared control socket as follows:

ssh -M -S ssh_socket -fnNTC ssh://user@host:9022

I have no problem executing commands using this socket; for example:

ssh -S ssh_socket ssh://user@host:9022 -t htop

But I want to mount a file system over the same shared socket, and cannot figure out the syntax. This mounts the file system, but not using the shared socket, so it asks for a password again:

sshfs -p 9022 user@host:/path /path

Can anyone help me figure out if what I want is even possible?

  • 1
    This is one reason that ~/.ssh/config is so useful. In this example, adding ControlMaster and ControlPath directives in your ssh config would also do the trick, avoiding the need to add command line options. – sitaram Jun 19 '20 at 22:35

It is possible.

Use -o ssh_command='ssh -S /full/path/to/ssh_socket'. From man 1 sshfs:

-o ssh_command=CMD
execute CMD instead of ssh.

sshfs placeholder:/remote/path /local/path -o ssh_command='ssh -S /full/path/to/ssh_socket'


  • In my Kubuntu the specified ssh_command runs in / regardless of the directory I run sshfs from. That's why this answer uses /full/path/to/ssh_socket, not just ssh_socket.
  • If you use ssh -S without -M, some options won't matter. The socket will matter in the first place. It is associated to some master connection where the port, the username and the host are already fixed. Therefore there is no need to use -p and you can use almost any placeholder instead of user@host. Even your second ssh command could be ssh -S ssh_socket -t whatever htop.
  • ssh://user@host:9022 syntax you used doesn't work with ssh from OpenSSH in my Kubuntu. What works is -p 9022 user@host.
  • Thanks! It is working. Btw I had noticed the destination seemed to be redundant when adding a connection to an existing socket, but it can appear in error messages if the connection fails, and I wasn't sure if a placeholder was technically valid, so I superstitiously left it alone. – Boann Jun 18 '20 at 20:42
  • @Boann The actual destination is at least as good placeholder as any. – Kamil Maciorowski Jun 18 '20 at 21:03

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.