I have a user directory mounted to ubuntu 12.04 with cifs. /etc/fstab contains a line;

//cb/share /home/cb cifs user=ubuntu,password=abc123,uid=cb,gid=users 0 0

The share mounts and works fine except for chown/chmod commands, which fail with;

$ sudo touch /home/cb/foo
$ sudo chown cb /home/cb/foo
chown: changing ownership of `/home/cb/foo': Permission denied

Forget that cifs is squashing uid and gid to the correct values (cb:users) already. There are some pre-existing scripts and utilities I need to use which fail because of the non-zero exit status returned by chown/chmod.

I naively tried mounting elsewhere (/mnt/cb), and then using bindfs to re-mount it, but this didn't work either.

sudo bindfs -o perms=0750,mirror=cb,group=users /mnt/cb /home/cb

Note, the only solution I'm looking for here is some way to configure the server/mount so that chmod/chown will fail quietly - i.e., return zero exit status.

1 Answer 1


Well, the trivial answer is to preempt the real chmod and chown with other programs that do not fail.  These can be scripts.  In /home/cab/bin (or any other convenient directory that you have full access to), create scripts called chmod and chown that say just


You can add exit 0 if you want, but 0 will be the default exit status if the script doesn’t do anything.  And then, of course, add /home/cab/bin to the beginning of your PATH environment variable.

If you want to be able to chmod and chown when you can, make the scripts say

/bin/"$(basename "$0")" "$@"
exit 0

replacing /bin with the directory that the real chmod and chown are in.  This executes the real command with the arguments to the script, and then exits with a status of 0 regardless of the exit status of the program.

And since the two scripts are identical (as long as the real chmod and chown commands are in the same directory on your system), you can write one and make the other a link to it.

  • Interesting. Is there a way to detect whether a file/dir is mounted? Then I could protect the call to the real chown/chmod.
    – CAB
    Jun 14, 2013 at 13:36
  • I’m not sure exactly what you mean, but try looking at $(df "$filename"). Jun 14, 2013 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .