各位。最近我開始使用 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 完全相同的命令,就像 autofs 一樣從 root 運行:
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 密鑰?