Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

http://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?

share|improve this question
    
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

1 Answer 1

up vote 3 down vote accepted

From the sudoers(5) man page:

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.