You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

挂载外置硬盘后新文件默认权限为777,如何修改为666?

Fixing Default 777 Permissions on Automounted External Drive

Hey there! Let's tackle that permission problem you're facing with your external drive. The root cause lies in the mount options configured in /etc/fstab—the system file that handles automatic drive mounts. Here's a step-by-step solution to get those default file permissions down to a maximum of 666:

Step 1: Edit Your /etc/fstab File

First, open the fstab file with root privileges to modify your drive's mount entry:

sudo nano /etc/fstab

Locate the line for your external drive—it starts with UUID= followed by your drive's unique ID, like this example (replace with your actual UUID and mount path):

UUID=1234-ABCD /mnt/external_drive vfat defaults 0 0

Step 2: Adjust Mount Options Based on Your Filesystem

The exact options you'll add depend on whether your drive uses a Linux-native filesystem or a non-native one:

For Non-Native Filesystems (FAT32/NTFS)

These filesystems don't store Linux-style permissions natively, so we use fmask (for files) and dmask (for directories) to set defaults directly:

  • fmask=011: Calculates to 777 - 011 = 666 for files, giving you rw-rw-rw permissions (exactly the "max 666" you want).
  • dmask=000: Sets directories to 777 (rwxrwxrwx), which is required to navigate and modify directory contents. If you prefer more restrictive directory permissions, use dmask=022 to get 755 (rwxr-xr-x).

Update your fstab line to look like this:

UUID=1234-ABCD /mnt/external_drive vfat defaults,fmask=011,dmask=000 0 0

For Linux-Native Filesystems (ext4, Btrfs, etc.)

These filesystems respect standard Unix permissions. Use the umask option to set a reverse mask:

  • umask=011: Results in files getting 666 (666 - 011 = 666) and directories getting 777 (777 - 011 = 777).

Your updated line will look like this:

UUID=abcd1234-efgh-ijkl-mnop-qrstuvwxyz1234 /mnt/external_drive ext4 defaults,umask=011 0 2

Step 3: Apply the Changes

Save the fstab file (in nano, press Ctrl+O, hit Enter, then Ctrl+X). Then unmount and remount the drive to activate the changes immediately:

sudo umount /mnt/external_drive
sudo mount /mnt/external_drive

If you can't unmount the drive (e.g., it's in use), restart your system instead.

Verify the Fix

Create a test file to confirm permissions are now correct:

touch /mnt/external_drive/test_file
ls -l /mnt/external_drive/test_file

You should see output showing permissions like -rw-rw-rw- (which corresponds to 666).

内容的提问来源于stack exchange,提问作者Luke W. Johnston

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:49:07