autofs 没有挂载 sshfs 点,而 sshfs 和 mount -t fuse 可以

autofs 没有挂载 sshfs 点,而 sshfs 和 mount -t fuse 可以

各位。最近我接触到了 autofs,现在想让我的日常生活更轻松一些。我有一个远程服务器,多年来我一直借助 sshfs 来共享文件。因此,我找到了一些教程,教你如何借助 autofs 来自动化 sshfs。以下是我的配置:

自动主控:

/home/user/autofs/ /etc/autofs/auto.sshfs uid=1000,gid=1000,--timeout=300,--ghost

自动.sshfs:

cux -fstype=fuse,port=222,rw,nodev,noatime,allow_other,IdentityFile=/home/user/.ssh/id_rsa :sshfs\#[email protected]\:/path/to/files

远程服务器仅接受 ssh 密钥,因此尝试访问挂载点的用户必须运行已导入密钥的 ssh 代理。

但是当我尝试访问挂载点时,我得到了:

Dec 31 18:56:37 ice automount[25565]: mount(generic): calling mount -t fuse -o uid=1000,gid=1000,port=222,rw,nodev,noatime,allow_other,IdentityFile=/home/user/.ssh/id_rsa sshfs#[email protected]:/path/to/files /home/user/autofs/cux
Dec 31 18:56:37 ice automount[25565]: spawn_mount: mtab link detected, passing -n to mount
Dec 31 18:56:37 ice automount[25565]: >> read: Connection reset by peer
Dec 31 18:56:37 ice automount[25565]: mount(generic): failed to mount sshfs#[email protected]:/path/to/files (type fuse) on /home/user/autofs/cux
Dec 31 18:56:37 ice automount[25565]: dev_ioctl_send_fail: token = 67
Dec 31 18:56:37 ice automount[25565]: failed to mount /home/user/autofs/cux

但是如果我使用 sshfs 挂载(从我的用户):

sshfs -p 222 server.com:/path/to/files /home/user/remote/cux -o reconnect

它成功了。即使我使用与 autofs 从 root 运行完全相同的命令,它也像 autofs 一样:

mount -t fuse -o uid=1000,gid=1000,port=222,rw,nodev,noatime,allow_other,IdentityFile=/home/user/.ssh/id_rsa sshfs#[email protected]:/path/to/files /home/user/autofs/cux

它也成功了。但问题似乎出在 ssh 密钥上。如果我从 root 运行 mount 命令而没有导入用户密钥 (su -),则会提示输入密码。有没有办法解决这个问题并让 autofs 使用访问挂载点的用户的 ssh 密钥?

相关内容