0

I am trying to give sudo ability without the need of passwords to specific files. So far I have:

employee ALL=(ALL:ALL) NOPASSWD: /home/file_name

The file has a simple chmod command, in the bash script it has at the very bottom "sudo chmod ..." and it will prompt me for the password.

I have tried it as:

employee ALL=(ALL:ALL) NOPASSWD: ALL

this will cause it to work, but I only want it to NOT ask for the password for this single file.

Eventually I want to also configure it to use root's password for sudo (I know it's not the most secure thing to do, and is not recommended). I know at that point you will need to enter in Defaults rootpw.

Does anyone know why this isn't working? I'm sure it's something silly.

  • 3
    You can configure sudo for commands to run with elevated privileges, not files... – gertvdijk Oct 14 '13 at 21:52
  • What would be the best way to do what I mentioned then? – James Boind Oct 14 '13 at 22:04
0

Do not put the

sudo chmod ...

command at the bottom of /home/file_name. Instead just put

chmod ...

And execute /home/file_name as sudo:

sudo /home/file_name

Do make sure that only root has write privileges for that file, or you're giving away the keys to the castle.

  • The file needs to be executable by multiple users that should not have sudo access. The goal is to still give them the chmod ability which lets them change the permissions of files that they may or may not own. – James Boind Oct 14 '13 at 22:12
  • @JamesBoind Yes. Just make the script in file_name do what it should do (such as checking that the user is allowed to chmod some specific file), make it root-writable and world-executable, and add a NOPASSWD rule for it to the sudoers file. Make sure that the file itself is exempt from being chmodded by any user. Also, if you have untrusted users, prepare for havoc. – zwets Oct 14 '13 at 22:35

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.