How to chown a file on a CIFS mount?

13,920

I'm not sure what symlink you are referring to. What you fail to change is the owner of /mnt/docs, the mount-point of your CIFS share. The mount-point owner changed to the user who mounted something onto it (root).

Since only root is able to mount, how can you change the owner of the mount-point (and its underlying content)? With the uid and gid options (and also, if necessary, the forceuid and forcegid options).

See the man-page of 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.

Therefore, your mount command should be:

mount -t cifs \
      -o username=****,password="****",uid=www-data \
      //192.168.1.10/Public/Documents/Docs \
      /mnt/docs
Share:
13,920

Related videos on Youtube

Drakes
Author by

Drakes

Every person you meet is your teacher in some way.

Updated on September 18, 2022

Comments

  • Drakes
    Drakes almost 2 years

    Here are my steps:

    mkdir /mnt/docs
    chown www-data:www-data /mnt/docs
    ls -l /mnt
    

    Positive results:

    drwxr-xr-x 2 www-data www-data 4096 Jan  6 01:14 docs
    drwxr-xr-x 2 root     root     4096 Dec  8 21:46 cdrom
    

    Now I mount the remote share successfully (I can touch files to it as root) like so

    mount -t cifs //192.168.1.10/Public/Documents/Docs -o username=****,password="****" /mnt/docs
    ls -l /mnt
    

    Negative results (the owner is back to root):

    drwxr-xr-x 2 root root    0 Jan 12 02:51 docs
    drwxr-xr-x 2 root root 4096 Dec  8 21:46 cdrom
    

    I then tried to chown the symlink like so (with -h)

    chown -h www-data:www-data /mnt/docs
    ls -l /mnt
    

    But the results are still

    drwxr-xr-x 2 root root    0 Jan 12 02:51 docs
    drwxr-xr-x 2 root root 4096 Dec  8 21:46 cdrom
    

    How can I mount the share to a local mount point as a non-root user? The goal is to let Apache be able to write to the remote share. Solutions for either Debian or CentOS systems are appreciated. Also, chmod as no effect either.


    Related: Symbolic link creation failing: change ownership issue

    • answerSeeker
      answerSeeker over 7 years
      use chown -R www-data:www-data for recursiveness
    • Drakes
      Drakes over 7 years
      But, without -h then the target gets chown'd, not the symlink. Also, it's an empty directory. Thanks.
    • answerSeeker
      answerSeeker over 7 years
      I think it has something to do with the way you created your samba share. If you follow this guide: help.ubuntu.com/community/…! maybe it'll help
    • answerSeeker
      answerSeeker over 7 years
      Is your samba share created on ubuntu or debian?
    • Drakes
      Drakes over 7 years
      I'm not sure where it resides. It's on a Linux machine that I can't SSH into.