Linux – chmod 777 is not changing the permissions to 777

linuxpermissions

I'm trying to change the permissions of temp_dir to 777. Why are these commands not accomplishing that? I'm using Linux by the way.

kylefoley@kfoley76:/mnt/disks$ chmod 777 /mnt/disks/temp_dir
kylefoley@kfoley76:/mnt/disks$ stat -c "%a %n" temp_dir
755 temp_dir

I also tried the verbose switch

kylefoley@kfoley76:/mnt/disks$ chmod -v 777 /mnt/disks/temp_dir
mode of '/mnt/disks/temp_dir' changed from 0755 (rwxr-xr-x) to 0777 (rwxrwxrwx)
kylefoley@kfoley76:/mnt/disks$ stat -c "%a %n" temp_dir
755 temp_dir

I also don't understand why I can't use sudo

kylefoley@kfoley76:/mnt/disks/temp_dir$ sudo chmod 777 fix_mistakes
chmod: cannot access 'fix_mistakes': Permission denied

Even when I log in as root user

kylefoley@kfoley76:/mnt/disks/temp_dir$ sudo -i
root@kfoley76:~# sudo chmod 777 /mnt/disks/temp_dir
chmod: cannot access '/mnt/disks/temp_dir': Permission denied

I should also add that this bug must have something to do with the fact that the directory in question is a gcsfuse mounted disk, available from gcloud. Other attempts to change permissions worked fine:

kylefoley@kfoley76:~$ mkdir hey
kylefoley@kfoley76:~$ stat -c "%a %n" hey
755 hey
kylefoley@kfoley76:~$ chmod 777 hey
kylefoley@kfoley76:~$ stat -c "%a %n" hey
777 hey

Best Answer

gcsfuse sets file and directory permissions when mounting. Specifically, the options are:

  • file_mode – Permission bits for files, in octal
  • dir_mode – Permissions bits for directories, in octal

Source: https://github.com/GoogleCloudPlatform/gcsfuse/blob/e0a0e0826897b09581c24065fb6a92912ee79d03/flags.go#L78

If you do not specify the options, the defaults are dir_mode=0755,file_mode=0644.

Source: https://github.com/GoogleCloudPlatform/gcsfuse/blob/e0a0e0826897b09581c24065fb6a92912ee79d03/flags.go#L51

These options apply to all files and directories in the mount. This FUSE file system does not have the capability of changing permissions for specific files or directories, which is why chmod does nothing.


Furthermore, gcsfuse has additional access restrictions that limit access to the user who mounted the file system. Details:

As a security measure, fuse itself restricts file system access to the user who mounted the file system (cf. fuse.txt). For this reason, gcsfuse by default shows all files as owned by the invoking user. Therefore you should invoke gcsfuse as the user that will be using the file system, not as root.

If you know what you are doing, you can override these behaviors with the allow_other mount option supported by fuse and with the --uid and --gid flags supported by gcsfuse. Be careful, this may have security implications!

Source: https://github.com/GoogleCloudPlatform/gcsfuse/blob/d25be2491879e3745c3ed3d8e816774defc1cc5c/docs/mounting.md#access-permissions

This is why you aren't able to access the mount from another user. To allow other users to access the mount, specify allow_other in your mount options.

Related Question