sshfs 按需安装

lon*_*nix 2 ssh sftp ubuntu fstab sshfs

我按照sshfs“按需”安装的说明进行操作,但它不起作用。

我将此添加到/etc/fstab

username@hostname:/ /mnt/remotes/hostname fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=/home/stanley/.ssh/my_rsa_key,allow_other,reconnect 0 0
Run Code Online (Sandbox Code Playgroud)

然后我跑了,sudo mount -a什么也没做。我也尝试过systemctl daemon-reload && systemctl restart proc-sys-fs-binfmt_misc.automount

所以我按照故障排除提示,并使用了这个:

username@hostname:/ /mnt/remotes/hostname fuse.sshfs ssh_command=ssh\040-vv,sshfs_debug,debug,_netdev,users,idmap=user,IdentityFile=/home/stanley/.ssh/my_rsa_key,allow_other,reconnect 0 0
Run Code Online (Sandbox Code Playgroud)

然后就跑了sudo mount -av。在一个单独的终端中,我可以访问该安装点。

所以 1) ssh 和 sftp 正在工作,2) sshfs 正在工作,3) 权限很好。

所以只有点播部分不起作用 - 我做错了什么?

lon*_*nix 5

这些说明令人困惑,尤其是对于不了解 systemd 的人来说。

正确的程序:

  1. 添加/etc/fstabusername@hostname:/ /mnt/remotes/hostname fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=/home/stanley/.ssh/my_rsa_key,allow_other,reconnect 0 0

  2. 跑步sudo systemctl daemon-reload。这将创建一个 systemd“单元文件”。

  3. 通过运行找出哪个单元文件systemctl list-unit-files --type automount。对我来说是的mnt-remotes-hostname.automount

  4. 启用它:sudo systemctl restart mnt-remotes-hostname.automount.

  5. cd /mnt/remotes/hostname或者ls /mnt/remotes/hostname它会自动创建 sftp 连接!

这可行,但我还不确定:

  • 有人说allow_other存在安全风险,我需要调查一下
  • 我不知道如何指定何时应自动卸载挂载(空闲时间有多少秒等)

如果有人能阐明这一点,请这样做。


更新 根据@sourcejedis的回答,停止安装必须按以下顺序完成:systemctl stop whatever.mount && systemctl stop whatever.automount并且不应使用umount mounpoint

  • `allow_other` 不应该允许权限升级,只允许拒绝服务(导致进程挂起,但它可以被杀死)。如果您不想要它提供的功能,我不会启用它,但如果您需要,我就会这样做:-)。 (2认同)
  • `x-systemd.idle-timeout=` 按照 `man systemd.mount` (2认同)