Under /some/long/and/annoying/path I have several scripts I need to give sudo access to, so I write in my /etc/sudoers (A):

Cmnd_Alias MY_SCRIPTS = /some/long/and/annoying/path/foo.sh, \
                        /some/long/and/annoying/path/bar.sh, \
                        /some/long/and/annoying/path/baz.sh, \
                        /some/long/and/annoying/path/qux.sh, \
                        /some/long/and/annoying/path/quux.sh, ...

But I don't like to repeat myself.

I realize I can just write (B):

Cmnd_Alias MY_SCRIPTS = /some/long/and/annoying/path/

To cover all the scripts under /some/long/and/annoying/path/ but I do like the control of specifying each file by name.

So my question is:

Is there a syntax such as (C):

MY_DIR = /some/long/and/annoying/path
Cmnd_Alias MY_SCRIPTS = $MYDIR/foo.sh, \
                        $MYDIR/bar.sh, \
                        $MYDIR/baz.sh, \
                        $MYDIR/qux.sh, \
                        $MYDIR/quux.sh, ...

That will be both explicit and DRY?

Note that: No is an acceptable answer that will let me carry on with my life.


I am not sure if this applies to your case but if you want all the scripts in a directory to be executed using sudo by a certain user, you can use the following construct:

username ALL=(ALL) NOPASSWD: /some/ungodly/long/directory/name/

notice the trailing /, which implies all files in the directory to be allowed by sudo.

Even if it is not the case for you, you can still make copies of your scripts in the sudoers command alias block, move them to a different directory and use the above construct.

  • Thanks @MelBurslan, but I already realized that this is an option (B). I might fallback to this solution, if what I really after is not possible – Chen Levy Mar 1 '16 at 15:05
  • It is going to be pointing the obvious, but instead of specifying the directory in the sudoers file, can you add it to the PATH and preserve PATH with Defaults env_keep directive in your sudoers file. Then, you do not have precede every executable by the directory name. Just a thought. – MelBurslan Mar 1 '16 at 15:06
  • I will accept this answer as "The C option is not supported in a sudoers file". Your other suggestions are valid. Thanks. – Chen Levy Mar 5 '16 at 17:46

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.