Linux sshfs 作为普通用户通过 fstab

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19971811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:20:39  来源:igfitidea点击:

Sshfs as regular user through fstab

linuxsshfs

提问by Sventimir

I'd like to mount a remote directory through sshfson my Debian machine, say at /work. So I added my user to fusegroup and I run:

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

sshfs [email protected]:/remote/dir /work

and everything works fine. However it would be very nice to have the directory mounted on boot. So I tried the /etc/fstabentry given below:

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

sshfs#[email protected]:/remote/dir /work     fuse      user,_netdev,reconnect,uid=1000,gid=1000,idmap=user  0   0

sshfsasks for password and mounts almost correctly. Almost because my regular userhas no access to the mounted directory and when I run ls -la /, I get:

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

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

How can I get it with right permissions trough fstab?

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

采纳答案by Sami Laine

Using option allow_otherin /etc/fstaballows other users than the one doing the actual mounting to access the mounted filesystem. When you booting your system and mounting your sshfs, it's done by user root instead of your regular user. When you add allow_otherother users than root can access to mount point. File permissions under the mount point still stay the same as they used to be, so if you have a directory with 0700 mask there, it's not accessible by anyone else but root and the owner.

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

So, instead of

所以,而不是

sshfs#[email protected]:/remote/dir /work     fuse      user,_netdev,reconnect,uid=1000,gid=1000,idmap=user  0   0

use

sshfs#[email protected]:/remote/dir /work     fuse      user,_netdev,reconnect,uid=1000,gid=1000,idmap=user,allow_other  0   0

This did the trick for me at least. I did not test this by booting the system, but instead just issued the mount command as root, then tried to access the mounted sshfs as a regular user.

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

回答by Martin Brousseau

Also to complement previous answer:

还要补充以前的答案:

  1. You should prefer the [user]@[host] syntax over the sshfs#[user]@[host] one.

  2. Make sure you allow non-root users to specify the allow_other mount option in /etc/fuse.conf

  3. Make sure you use each sshfs mount at least once manually while root so the host's signature is added to the .ssh/known_hosts file.

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

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

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

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

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

REF: https://wiki.archlinux.org/index.php/SSHFS

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

回答by Marten Sytema

Also, complementing the accepted answer: there is a need that the user on the target has a right to shell, on target machine: sudo chsh username-> /bin/bash.

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

I had a user who had /bin/false, and this caused problems.

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