The issue with the wildcard is that it's expanded by the shell, before running the sudo
command.
If only authduser
will be able to list files under /mounted/filesystem/path/
, but not your user who is running the sudo
command, then the shell will not be able to expand the wildcard and will pass it unmodified. Since ls
itself doesn't expand wildcards, this will result in the error you're seeing.
See Why isn't this sudo mv operation with wildcard working? for more details on that.
For a solution to this problem, you can use sudo
's -s
argument, which spawns a shell as the target user (rather than simply executing a command directly), in which case if you also give it a command, it will be passed to the shell using the -c
option (which is the usual option for the shell to interpret and execute a command, including wildcard expansion.)
In that case, you'll want to put the command within quotes (preferably single quotes), so that the shell running the sudo
command will not try to interpret the command, only the one spawned by sudo
as the target user:
# sudo -u authduser -s 'ls /mounted/filesystem/path/*.user.js'
See the man page of sudo for more details, in particular take a look at the -s
option.
UPDATE: It's not really possible to use sudo -s
with a command here. See “sudo -s ” runs command in a shell, but wildcards or metacharacters not working for more details.