Windows – CentOS 7 mounted windows share is read only

centos7mountnetwork-sharesambawindows

I mounted a Windows share on CentOS 7, but I have read only access to it. I need write access.

Commands used to mount the share…

sudo mkdir /media/shared
sudo chmod 777 /media/shared
sudo vim /etc/fstab
//192.168.16.25/shared /media/shared cifs 
username=XXXX,password=XXXX,uid=1000,gid=1000 0 0

It mounts fine, but the owner is now "admin" and it's read only…

$ ls -lrt
total 8
drwxr-xr-x 2 admin admin 4096 Aug  7 18:11 shared

And I can't change it

$ sudo chown -R root shared
chown: changing ownership of ‘shared/System Volume Information’: 
Permission denied
sudo chown: changing ownership of ‘shared’: Permission denied
$ sudo chmod 777 shared
chmod: changing permissions of ‘shared’: Permission denied

What am I missing? And on the Windows Server, the drive is shared with "Everyone" with full access.

Fixed! Here is the solution to what I changed the config to in fstab…

//192.168.16.25/shared /mnt/shared cifs username=XXXX,password=XXXX,uid=0,gid=0,file_mode=0777,dir_mode=0777 0 0

Best Answer

Please read up on file ownership and permissions in the mount.cifs manual, which is part of the cifs-utils RPM package:

File And Directory Ownership And Permissions

The core CIFS protocol does not provide unix ownership information or mode for files and directories. Because of this, files and directories will generally appear to be owned by whatever values the uid= or gid=options are set, and will have permissions set to the default file_mode and dir_mode for the mount. Attempting to change these values via chmod/chown will return success but have no effect.

...

Basically you are using the mount options uid=1000,gid=1000 to force a specific owner of the mounted share, which is what makes your chown command fail.
If you want to change the owner, simply mount the share with the correct owner in the uid=?,gid=? mount options in /etc/fstab instead of using chown and use file_mode=? and dir_mode=? instead of chmod.