Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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
up vote 4 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


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.