4

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?

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

From the sudoers(5) man page:

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

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.