Sshfs作为常规用户通过fstab

时间:2013-11-14 07:20:21

标签: linux sshfs

我想在我的Debian机器上通过sshfs挂载一个远程目录,比如/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获得正确的权限?

3 个答案:

答案 0 :(得分:26)

allow_other中使用选项/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。

答案 1 :(得分:2)

另外补充以前的答案:

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

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

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

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

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

答案 2 :(得分:0)

此外,作为已接受的答案的补充:在目标计算机上,目标计算机上的用户必须拥有sudo chsh username-> /bin/bash上的外壳程序权限。

我有一个用户使用/ bin / false,这会引起问题。