Linux
使用 sshfs 掛載和寫入文件權限
我嘗試 sshfs 掛載一個遠端目錄,但掛載的文件不可寫。我已經沒有想法或方法來調試它了。我應該在遠端伺服器上檢查什麼嗎?
我在 Xubuntu 14.04 上。我掛載了 14.04 Ubuntu 的遠端目錄。
local $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS Release: 14.04 Codename: trusty
我改變了 /etc/fuse.conf
local $ sudo cat /etc/fuse.conf # /etc/fuse.conf - Configuration file for Filesystem in Userspace (FUSE) # Set the maximum number of FUSE mounts allowed to non-root users. # The default is 1000. #mount_max = 1000 # Allow non-root users to specify the allow_other or allow_root mount options. user_allow_other
我的使用者在保險絲組中
local $ sudo grep fuse /etc/group fuse:x:105:MY_LOACL_USERNAME
我使用(嘗試使用/不使用 sudo、default_permissions、allow_other 的組合)安裝遠端目錄:
local $sudo sshfs -o allow_other,default_permissions -o IdentityFile=/path/to/ssh_key REMOTE_USERNAME@REMOTE_HOST:/remote/dir/path/ /mnt/LOCAL_DIR_NAME/
對
REMOTE_USERNAME
目錄/文件(在遠端伺服器上)具有寫權限。我在沒有 sudo、default_permissions 的情況下嘗試了上述命令,並且在所有情況下我都得到:
local $ ls -al /mnt/LOCAL_DIR_NAME/a_file -rw-rw-r-- 1 699 699 1513 Aug 12 16:08 /mnt/LOCAL_DIR_NAME/a_file local $ test -w /mnt/LOCAL_DIR_NAME/a_file && echo "Writable" || echo "Not Writable" Not Writable
澄清 0
回應 user3188445 的評論:
$ whoami LOCAL_USER $ cd $ mkdir test_mnt $ sshfs -o allow_other,default_permissions -o IdentityFile=/path/to/ssh_key REMOTE_USERNAME@REMOTE_HOST:/remote/dir/path/ test_mnt/ $ ls test_mnt/ I see the contents of the dir correctly $ ls -al test_mnt/ total 216 drwxr-xr-x 1 699 699 4096 Aug 12 16:42 . drwxr----- 58 LOCAL_USER LOCAL_USER 4096 Aug 17 15:46 .. -rw-r--r-- 1 699 699 2557 Jul 30 16:48 sample_file drwxr-xr-x 1 699 699 4096 Aug 11 17:25 sample_dir $ touch test_mnt/new_file touch: cannot touch ‘test_mnt/new_file’: Permission denied # extra info: SSH to the remote host and check file permissions $ ssh REMOTE_USERNAME@REMOTE_HOST # on remote host $ ls -al /remote/dir/path/ lrwxrwxrwx 1 root root 18 Jul 30 13:48 /remote/dir/path/ -> /srv/path/path/path/ $ cd /remote/dir/path/ $ ls -al total 216 drwxr-xr-x 26 REMOTE_USERNAME REMOTE_USERNAME 4096 Aug 12 13:42 . drwxr-xr-x 4 root root 4096 Jul 30 14:37 .. -rw-r--r-- 1 REMOTE_USERNAME REMOTE_USERNAME 2557 Jul 30 13:48 sample_file drwxr-xr-x 2 REMOTE_USERNAME REMOTE_USERNAME 4096 Aug 11 14:25 sample_dir
這個問題在一個linux 郵件列表中得到了回答;為了完整起見,我在此處發布了翻譯後的答案。
解決方案
解決方案是不要同時使用選項
default_permissions
和allow_other
(我在最初的實驗中沒有嘗試過)。解釋
問題似乎很簡單。當您
default_permissions
在 fusermount 中提供選項時,fuse 對 fuse mount 的權限控制由核心而不是fuse處理。這意味著 REMOTE_USER 的 uid/gid 沒有映射到 LOCAL_USER (sshfs.c IDMAP_NONE)。它的工作方式與沒有映射的簡單 nfs fs 相同。因此,如果 uid/gid 數字不匹配,則禁止訪問是有意義的。
如果您有選項
allow_other
,則此目錄只能由具有 uid 699 的本地使用者寫入(如果存在)。來自保險絲的人:
'default_permissions' By default FUSE doesn't check file access permissions, the filesystem is free to implement its access policy or leave it to the underlying file access mechanism (e.g. in case of network filesystems). This option enables permission checking, restricting access based on file mode. It is usually useful together with the 'allow_other' mount option. 'allow_other' This option overrides the security measure restricting file access to the user mounting the filesystem. This option is by default only allowed to root, but this restriction can be removed with a (userspace) configuration option.