0

I have a Windows shared drive that I have mounted on my CentOS 7 machine using the instructions by Red Hat that I would now like to create and edit files on. However I must be elevated to create and edit files on any folder on the drive. I have tried using chmod to allow all users access, but to no avail, and have even tried unmounting/remounting the drive.

How can I get non-elevated access to the drive?

(I am creating these files using Matlab, and Matlab can't be run via sudo, so simply staying elevated is not an option).

Terminal Printout

[millironx@mymachine ~]$ sudo umount /mnt
[millironx@mymachine ~]$ sudo mount -t cifs -o username=millironx,password=mypassword,domain=AD //files.example.com/shared /mnt
[millironx@mymachine ~]$ cd /mnt/matlab-program
[millironx@mymachine matlab-program]$ touch testfile
touch: cannot touch 'testfile': Permission denied
[millironx@mymachine matlab-program]$ sudo chmod +rwx /mnt/matlab-program
[millironx@mymachine matlab-program]$ touch testfile
touch: cannot touch 'testfile': Permission denied
[millironx@mymachine matlab-program]$ sudo touch testfile
[millironx@mymachine matlab-program]$ ls
testfile
[millironx@mymachine matlab-program]$ rm testfile
rm: remove write-protected regular empty file 'testfile`? y
rm: cannot remove 'testfile': Permission denied
[millironx@mymachine matlab-program]$ sudo rm testfile
[millironx@mymachine matlab-program]$ sudo matlab
sudo: matlab: command not found
1

You need uid= and maybe gid= mount option. See man 8 mount.cifs:

uid=arg
sets the uid that will own all files or directories on the mounted filesystem when the server does not provide ownership information. It may be specified as either a username or a numeric uid. When not specified, the default is uid 0. The mount.cifs helper must be at version 1.10 or higher to support specifying the uid in non-numeric form. See the section on File And Directory Ownership And Permissions below for more information.

gid=arg
sets the gid that will own all files or directories on the mounted filesystem when the server does not provide ownership information. It may be specified as either a groupname or a numeric gid. When not specified, the default is gid 0. The mount.cifs helper must be at version 1.10 or higher to support specifying the gid in non-numeric form. See the section on File And Directory Ownership And Permissions below for more information.

[…]

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. […]

This section also mentions a scenario where "the client and server negotiate unix extensions" and a scenario where "it's also possible to emulate them locally on the server" etc.

In your case simple uid= and gid= should suffice. Note they specify Unix user and group, uid= and username= are different and in general may take different values.

sudo mount -t cifs -o uid=millironx,gid=users,username=millironx,password=mypassword,domain=AD //files.example.com/shared /mnt

You may also find this question useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.