3

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?

Boann
  • 1,165

1 Answers1

3

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'

Notes:

  • 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.