5

I have a number of users of a desktop machine, who each have a folder on a remote samba server. I am trying to set up per-user mounting of these network folders following the instructions here:

https://askubuntu.com/questions/67405/auto-mounting-network-shares-per-user

That article recommends adding the following line to sudoers:

user ALL= NOPASSWD: /bin/mount -t cifs -o cred=/home/user/.Music.cred //server/music /home/user/MyMusicFolder

That command works fine, but I need to mount the shares so that they are owned by a specific group. I have tried changing the line to read like this:

user ALL= NOPASSWD: /bin/mount -t cifs -o cred=/home/user/.Music.cred,gid=xxx //server/music /home/user/MyMusicFolder

But with the addition of the ,gid=xxx the sudoers file no longer parses correctly. I assume this is because the NOPASSWD command actually takes a comma separated list of arguments so I need to escape the comma in the command. I can do this using a backslash, like so:

user ALL= NOPASSWD: /bin/mount -t cifs -o cred=/home/user/.Music.cred\,gid=xxx //server/music /home/user/MyMusicFolder

Now the sudoers file will parse, and I can run the mount command with sudo without being asked for a password. Unfortunately I now get this error:

Sorry, user is not allowed to execute '/bin/ls /home/' as root on ubuntu.

when I try to run any other command. I don't get this error if I remove the \,gid=xxx from the line. So what is the right way to escape commas in the sudoers file?

1
  • Try surrounding the comma with single quotes like ',' as I have found some documentation that mentions that for commands like this.
    – Lipongo
    Commented Dec 31, 2012 at 0:00

1 Answer 1

13

From the sudoers(5) man page:

Note that the following characters must be escaped with a '\' if they are used in command arguments: ',', ':', '=', '\'.

You must log in to answer this question.

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