我刚刚安装了 ubuntu 22.04,并且有一个格式化为 exFAT 的外部 USB 硬盘。我可以以 root 身份写入它,但不能以用户身份写入它。我想允许所有用户写入此驱动器。如果我尝试添加写入权限,则没有任何变化。
以下是相关内容/etc/fstab
:
/dev/disk/by-id/usb-Hitachi_HDS5C3020ALA632_FFFACFF0FD000000FF4221F302FD4F-0:0-part1 /media/external auto nosuid,nodev,nofail,x-gvfs-show 0 0
下面是一些说明我的问题的示例控制台输出:
touch: cannot touch 'external/foo.txt': Permission denied
x@x-U4:/media$ ls -al
total 520
drwxr-xr-x 3 root root 4096 Feb 6 21:12 .
drwxr-xr-x 20 root root 4096 Feb 5 11:29 ..
drwxr-xr-x 4 root root 524288 Feb 7 22:52 external
x@x-U4:/media$ chmod 777 external
chmod: changing permissions of 'external': Operation not permitted
x@x-U4:/media$ sudo !!
sudo chmod 777 external
x@x-U4:/media$ sudo chmod 777 external
x@x-U4:/media$ ls -al
total 520
drwxr-xr-x 3 root root 4096 Feb 6 21:12 .
drwxr-xr-x 20 root root 4096 Feb 5 11:29 ..
drwxr-xr-x 4 root root 524288 Feb 7 22:52 external
x@x-U4:/media$ sudo chmod o+w external/
x@x-U4:/media$ ls -al
total 520
drwxr-xr-x 3 root root 4096 Feb 6 21:12 .
drwxr-xr-x 20 root root 4096 Feb 5 11:29 ..
drwxr-xr-x 4 root root 524288 Feb 7 22:52 external
x@x-U4:/media$ touch external/foo.txt
touch: cannot touch 'external/foo.txt': Permission denied
x@x-U4:/media$ sudo touch external/foo.txt
x@x-U4:/media$ ls external/*.txt
external/foo.txt
知道发生了什么事以及我如何让用户写入/media/external
?
答案1
要为所有用户启用写权限,请将/etc/fstab
行更改为以下内容。
/dev/disk/by-id/usb-Hitachi_HDS5C3020ALA632_FFFACFF0FD000000FF4221F302FD4F-0:0-part1 /media/external auto rw,user,uid=1000,dmask=0000,fmask=0000,nosuid,nodev,nofail,x-gvfs-show 0 0
參考文獻:“dmask”和“fmask”挂载选项