How to run a single command in rhel for a particular user

e.g: only ls command should execute, if we try for other commands we should get a error like permission denied

I am uisng visduo file and created a user and assigned a permission like

abhitest        ALL=(ALL)       /bin/ls

and I tried too abhitest ALL=/bin/ls

but its not working

  • This would allow user abhitest to run sudo -u <any other user> ls <any parameters>, i.e. the user would be able to run the ls command with any parameters as any user, including root. But it would have no effect at all for commands run as user abhitest: if you want that, you need to set up a restricted shell for that user. – telcoM Mar 6 '18 at 10:37

I supposed you refer to sudo mecanism (visudo is part of sudo)


abhitest        ALL=(ALL)       /bin/ls

you should be able to run, as abhitest

sudo /bin/ls 
  • you will be asked root abhitest's password. (this may or may not what you intend, assuming a real command)

try ti use in sudoers

abhitest        ALL=(ALL) NOPASSWD:      /bin/ls /some/secret/dir

you should be able, as abhitest to run

sudo /bin/ls /some/secret/dir

note that both

sudo ls /some/secret/dir
sudo /bin/ls /some/other/secret/dir

won't "work". In first case ls is not /bin/ls, in second case directories are different.

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.