I'm mounting a samba share from one CentOS server to another using:

mount -t cifs -o blarg,password // /var/blarg/copy-to

When I do this the permissions of /var/blarg/copy-to change to admin:admin. When I unmount using umount // the permissions change back. I don't want this to happen as this affects some other functions.

How can I prevent the permissions changing to admin?


This is normal unix behavior, however you can make cifs ignore remote user information.

mount -t cifs -o \
    user=blarg,password=blarg,nounix,uid=0,gid=0 \
    // /var/blarg/copy-to

This makes all files look like they are owned by root:root. All files created will be owned by the user who mounted it; in this case, blarg.

nounix does a bit more then just disabling user information, it disables all posix extensions. If this is a windows mount, this is what you want. If not you can change nounix to forceuid,forcegid.

  • This returns "improperly formatted UNC name. // does not begin with \\ or //" – blarg Apr 15 '14 at 8:47
  • I think this worked. Although it asked for root password :S "mount -t cifs -o \ blarg,password,forceuid,forcegid,uid=501,gid=501 \\\\ /var/blarg/copy-to" – blarg Apr 15 '14 at 9:05
  • Yea, to mount as another user, you will need to be root. CIFS is one of the few edge cases were user mounting is normal. uid and gid will default to the current user if missing. – Georgyo Apr 15 '14 at 15:31

As per man mount.cifs:

       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.

if you want to force the uid to an expected one, use uid. The same applies to groups (gid).


$ mount -t cifs // /var/blarg/copy-to -o blarg,password -o uid=1000,gid=100

To find uid and gid, you can use getent command:

$ getent passwd <username>    

where first 1000 is uid and 1005 gid (values change, not order).

  • This returns "-bash: -o: command not found" – blarg Apr 15 '14 at 8:26
  • Someone edited the content.. I corrected it. For some reasons backsticks were introduced and shouldn't have been there – UnX Apr 15 '14 at 12:14

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.