Change permissions of windows mounted folder from linux

43,681

Solution 1

Is it possible to change permission on the mounted windows folder from Linux command(chmod)?

No. CIFS much like NTFS is a virtual filesystem so chmod has no affect. And changing the permission of the mount point before anything is mounted to it will have no affect either since the permissions after a mount always replace the permissions before the mount.

If the desired permissions is 777 change your mount command to include those permissions: dir_mode=0777,file_mode=0777. I would also get in the habit of adding the nounix option although for a Windows share it won't do much.

So try this instead:

mount -t cifs -o username=<share user>,password=<share password>,dir_mode=0777,file_mode=0777,nounix //WIN_PC_IP/<share name> /mnt

And I would agree that a better mount point would be something under /mnt rather than /mnt itself.

Solution 2

Firstly, only root (by default) may change permissions to the /mnt directory itself since it's owned by root:root - so attempting to modify it's permissions will fail as non-root.

You likely want to make this easier on yourself by creating a subdirectory inside /mnt, changing it's permissions, then mounting there.

First unmount anything already:

sudo umount /mnt

Next create a subdirectory where you will mount the share

sudo mkdir /mnt/share

Now change the permissions to be owned by the user you want to modify it:

sudo chown foo:foo /mnt/share

Where foo:foo is for the user foo, which should be your username.

Lastly mount to the /mnt/share location instead:

sudo mount -t cifs -o username=xxx,password=xxx //WIN_PC_IP/<share name> /mnt/share

If you still have problems with the files inside /mnt/share not being owned by the correct user you might need to specify the uid=xxx,gid=xxx in the mount options.

Share:
43,681

Related videos on Youtube

harish chava
Author by

harish chava

Updated on September 18, 2022

Comments

  • harish chava
    harish chava over 1 year

    I mounted windows share to linux(rhel7) using

    mount -t cifs -o username=<share user>,password=<share password> //WIN_PC_IP/<share name> /mnt
    

    I successfully mounted it. From Linux I tried to change permissions on the mounted folder then it gave me the error.

    chmod: changing permissions of ‘/mnt/’: Permission denied

    chmod -R 777 /mnt
    

    How can I change permissions of the mounted folder in Linux?

    Is it possible to change permission on the mounted windows folder from Linux command(chmod)?

    • Kristopher Ives
      Kristopher Ives over 5 years
      Also note that Ask Ubuntu is for Ubuntu related questions you might want to see unix.stackexchange.com for RHEL related questions.
  • harish chava
    harish chava over 5 years
    I am trying to change permissions using the root user only
  • harish chava
    harish chava over 5 years
    It I tries to change permissions on /mnt/ using chmod 777 /mnt it is giving error permission denied. But If I make new folder in /mnt say /mnt/share then If I tries to change permissions using chmod 777 /mnt/share It is not theowing any error but permissions were not getting changed. Why is this happening?
  • harish chava
    harish chava over 5 years
    /mnt Which I mentioned in the question is in /home/mnt not directly /mnt.
  • Shayan
    Shayan over 4 years
    @Morbius1 What does , do? I can't find dir_mode or file_mode or nounix in manual pages of mount
  • Shayan
    Shayan over 4 years
    @what's xxx in uid and gid?
  • Shayan
    Shayan over 4 years
    Ohhhh... I should separate the options with ,. I found it in man mount.cifs. I first had to find which manpage, man -K file_mode worked nicely.
  • Shayan
    Shayan over 4 years
    Ohhh it's user id and group id. id -u and id -g. works nicely
  • kapitan
    kapitan over 3 years
    i just added dir_mode=0777,file_mode=0777 as instructed and my mount folder is now writable. [+1]
  • Evan Carroll
    Evan Carroll over 3 years
    You can just use set the uid and gid to the actual name of the user and group respectively, you don't have to manually resolve this to a number. It's not 1978.