20

我想sshfs在我的 Debian 机器上挂载一个远程目录,比如在/work. 所以我将我的用户添加到fuse组中并运行:

sshfs user@remote.machine.net:/remote/dir /work

一切正常。但是,在启动时安装目录会非常好。所以我尝试了/etc/fstab下面给出的条目:

sshfs#user@remote.machine.net:/remote/dir /work     fuse      user,_netdev,reconnect,uid=1000,gid=1000,idmap=user  0   0

sshfs要求输入密码并几乎正确安装。几乎是因为我的常规user无法访问已安装的目录,当我运行时ls -la /,我得到:

d?????????   ? ?        ?               ?            ? work

如何通过 fstab 获得正确的权限?

4

3 回答 3

29

使用选项allow_otherin/etc/fstab允许执行实际挂载的其他用户访问挂载的文件系统。当你引导你的系统并挂载你的 sshfs 时,它是由 root 用户而不是你的普通用户完成的。当您添加allow_other除 root 以外的其他用户时,可以访问挂载点。挂载点下的文件权限仍然与以前相同,因此,如果您在那里有一个带有 0700 掩码的目录,那么除了 root 和所有者之外,其他任何人都无法访问它。

所以,而不是

sshfs#user@remote.machine.net:/remote/dir /work     fuse      user,_netdev,reconnect,uid=1000,gid=1000,idmap=user  0   0

利用

sshfs#user@remote.machine.net:/remote/dir /work     fuse      user,_netdev,reconnect,uid=1000,gid=1000,idmap=user,allow_other  0   0

这至少对我有用。我没有通过引导系统来测试这一点,而是以 root 身份发出 mount 命令,然后尝试以普通用户身份访问挂载的 sshfs。

于 2013-11-14T08:30:15.750 回答
4

还要补充以前的答案:

  1. 您应该更喜欢 [user]@[host] 语法而不是 sshfs#[user]@[host] 语法。

  2. 确保允许非 root 用户在 /etc/fuse.conf 中指定 allow_other 挂载选项

  3. 确保在 root 时手动使用每个 sshfs 挂载至少一次,以便将主机的签名添加到 .ssh/known_hosts 文件中。

    $ sudo sshfs [user]@[host]:[remote_path] [local_path] -o allow_other,IdentityFile=[path_to_id_rsa]

参考:https ://wiki.archlinux.org/index.php/SSHFS

于 2017-04-15T13:15:10.580 回答
0

此外,补充已接受的答案:目标用户需要在目标机器上拥有 shell 权限:sudo chsh username-> /bin/bash

我有一个用户有 /bin/false,这导致了问题。

于 2019-02-06T14:16:22.960 回答