Sshfs breaks symlinks from SFTP server

mountsftpsshfssymlink

Does anyone know how to mount a remote SFTP path via SSHFS so that you can work with symlinks? When I do this, all the symlinks I create point to the wrong files (not the ones I linked to.) All the symlinks I am interested in are relative (not absolute) so having them appear exactly as they do on the remote machine would be ideal.

Using sshfs with the default mount options, I cannot create a symlink to another file in the current directory:

$ cd /mnt/path/to/sshfs/mount
$ ln -s ./test ./test2
$ ls test2
lrwxrwxrwx 1 root webusers   11 Jul  3 09:11 test2 -> /test

Which is obviously incorrect, as the link target is in the current directory (./test), but here you can see that sshfs creates a link to /test which is incorrect – the link target is /mnt/path/to/sshfs/mount/test not /test.

By adding the transform_symlinks option when I mount the sshfs filesystem, I get a relative link instead with the same command, but it still points to the wrong place:

$ cd /mnt/path/to/sshfs/mount
$ ln -s ./test ./test2
$ ls test2
lrwxrwxrwx 1 root webusers   11 Jul  3 09:13 test2 -> ../../../test

Here I tried to link to ./test in the current directory, but instead I got a link to ../../../test three levels up!

Connecting with the command line SFTP client sftp instead of mounting with sshfs does work however:

sftp> open ...
sftp> symlink test test2
...
$ cd /mnt/path/to/sshfs/mount
$ ls test2
lrwxrwxrwx 1 root webusers   11 Jul  3 09:13 test2 -> test

So this tells me the remote SFTP server is working fine (since I can create symlinks with a dedicated SFTP client), but for some reason I am unable to create any working symlinks though sshfs.

Oddly enough, when I use sshfs to mount a path on an SSH server providing shell access (as opposed to an SFTP-only server) the symlinks work fine – I can create them correctly. It only seems to be problematic when connected to an SFTP-only server.

What am I doing wrong? Is there a special option I have to pass to sshfs when I am connecting to an SFTP server to make the symlinks work?

Best Answer

To transform remote absolute (starting with /) symlinks to be relative to the sshfs mount point, use the follow_symlinks option:

sshfs -o follow_symlinks ...

The transform_symlinks option does nothing for me, see this issue.

Related Question