sshfs breaks symlinks from SFTP server
Solution 1
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.
Solution 2
I've seen the behavior you describe before, but testing it now I can create symlinks just fine on an sshfs-mounted directory:
$ touch T
$ ln -s T L
$ ls -l T L
lrwxrwxrwx 1 user user 1 Apr 9 16:10 L -> T
-rw-rw-r-- 1 user user 0 Apr 9 16:10 T
$ echo hello >> L
$ cat T
hello
$ pwd
/home/user/oak/tmp
$ mount | grep oak
user@oak: on /home/user/oak type fuse.sshfs (rw,nosuid,nodev,user=user)
I upgraded sshd on the remote about 4 months ago. The old version would have been several years old. Maybe the upgrade fixed the issue. This may give some clue as to what I'm using now:
$ ssh oak 'ident $(which sshd)' | grep ssh
/usr/sbin/sshd:
$NetBSD: sshd.c,v 1.13.4.1 2015/04/30 06:07:31 riz Exp $
$NetBSD: sshpty.c,v 1.2.26.1 2015/04/30 06:07:31 riz Exp $
$NetBSD: sshlogin.c,v 1.4.22.1 2015/04/30 06:07:31 riz Exp $
I have not done anything to change sshfs, except what Ubuntu does automatically.
HTH.
Related videos on Youtube
Malvineous
Updated on September 18, 2022Comments
-
Malvineous almost 2 years
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?
-
Admin almost 11 yearsI don't understand your question: sshfs always uses SFTP. What do you mean by “via ssh instead of sftp”? It looks like you're having trouble with one particular SFTP server. If you use an SFTP client, what does it show when you run
ls -l
on your test symlinks? -
Admin almost 11 yearsSorry, when I say
sftp
in lowercase I mean the command line SFTP interface, i.e./usr/bin/sftp
. My last example in the post is when I make the symlink using this SFTP client, just as you request. -
Admin almost 11 yearsI still have no idea what you mean. Please edit your post to clarify what you're doing locally, what you're doing over an sshfs mount without the
transform_symlinks
option, what you're doing over an ssh mount with thetransform_symlinks
option, and what you're doing with an sftp client. Symlinks do work normally over SSHFS, so the answer to your first sentence is “nothing” — either you've encountered a bug or you aren't typing the right commands, but your reporting is too unclear to know what is wrong. -
Admin almost 11 yearsI have tried to clarify what I am asking for as best I can, but I'm not quite sure what you are after as the question does seem clear to me. If it is still unclear, please tell me specifically what parts do not make sense and why, and I will try to focus on those bits. Hopefully your questions are now answered.
-