You are not logged in.

#1 2014-07-14 17:42:46

rchipman
Member
Registered: 2014-07-14
Posts: 11

[SOLVED] sudoers NOPASSWD problems

I have been trying to solve what ought to be a fairly easy problem for a while now, but research both on google and here on the Arch forums/wiki has yet to turn up a solution.

I am trying to disable sudo prompts for all the scripts in a given directory. This is my /etc/sudoers file:

## Aliases
Cmnd_Alias RCHIPMANSCRIPTS = /home/rchipman/scripts/*

## User Privilege Specification
root ALL=(ALL) ALL
%wheel ALL=(ALL) ALL
rchipman ALL=(ALL) NOPASSWD: RCHIPMANSCRIPTS 

But for some reason, it still prompts for a password when I try to run a script in that directory. Trying to specify a particular script is similarly unsuccessful:

## Aliases
Cmnd_Alias RCHIPMANSCRIPTS = /home/rchipman/scripts/backlight.sh

## User Privilege Specification
root ALL=(ALL) ALL
%wheel ALL=(ALL) ALL
rchipman ALL=(ALL) NOPASSWD: RCHIPMANSCRIPTS 

However, disabling all sudo prompts for my account does work:

## Aliases
Cmnd_Alias RCHIPMANSCRIPTS = /home/rchipman/scripts/*

## User Privilege Specification
root ALL=(ALL) ALL
%wheel ALL=(ALL) ALL
rchipman ALL=(ALL) NOPASSWD: ALL

Can anyone spot an error here? Thanks in advance for the help!

Last edited by rchipman (2014-07-14 19:12:23)

Offline

#2 2014-07-14 18:01:08

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] sudoers NOPASSWD problems

Is that the entire contents of your sudoers file?

If not can you post the exact file when it's not working (I have an idea but need to see your sudoers file).


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2014-07-14 18:03:46

rchipman
Member
Registered: 2014-07-14
Posts: 11

Re: [SOLVED] sudoers NOPASSWD problems

That is the entirety of my sudoers file -- nothing else in there to muck it up yet

Offline

#4 2014-07-14 18:09:04

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [SOLVED] sudoers NOPASSWD problems

Based on my limited understanding of the sudoers syntax, it seems like that should work. But try commenting out the wheel entry and doing all privileges by your username eg.

## Aliases
Cmnd_Alias RCHIPMANSCRIPTS = /home/rchipman/scripts/*

## User Privilege Specification
root ALL=(ALL) ALL
#%wheel ALL=(ALL) ALL
rchipman ALL=(ALL) ALL, NOPASSWD: RCHIPMANSCRIPTS

But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#5 2014-07-14 18:09:13

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] sudoers NOPASSWD problems

Sorry, no help from me then.

Just FYI the sudoers file is very specific about the order of its entries, I wanted to check that yours were in the correct order but as your rchipman entry is already at the bottom then it's correct.

Last edited by Slithery (2014-07-14 18:10:51)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#6 2014-07-14 18:16:45

rchipman
Member
Registered: 2014-07-14
Posts: 11

Re: [SOLVED] sudoers NOPASSWD problems

Could there be some issue with the alias or the format of the filepath? As far as I can tell that is correct as well, but I just don't understand why NOPASSWD: ALL works while nopasswd for a given folder or script will not.

Offline

#7 2014-07-14 18:25:44

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] sudoers NOPASSWD problems

Are you rebooting or logging out/in between changes?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#8 2014-07-14 18:27:57

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [SOLVED] sudoers NOPASSWD problems

@slithery

Just opening a new session (new vterm or tab) should be all that's necessary.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#9 2014-07-14 18:28:44

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] sudoers NOPASSWD problems

Try this...

rchipman ALL=(ALL) NOPASSWD: /home/rchipman/scripts/

Last edited by Slithery (2014-07-14 18:31:14)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#10 2014-07-14 18:30:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,571
Website

Re: [SOLVED] sudoers NOPASSWD problems

I'm not sure if it will make a difference, but your use fits much better to the description of a Cmnd_List than Cmnd_Alias from the man page.

But more on point, do these scripts take parameters?  Do scripts that do not require parameters work?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#11 2014-07-14 18:33:31

rchipman
Member
Registered: 2014-07-14
Posts: 11

Re: [SOLVED] sudoers NOPASSWD problems

Nope, removing the * doesn't seem to change anything... neither does skipping the alias and writing the path right after the NOPASSWD

Last edited by rchipman (2014-07-14 18:34:22)

Offline

#12 2014-07-14 18:37:34

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [SOLVED] sudoers NOPASSWD problems

I tested something similar to OP's example and it worked:

## Aliases
Cmnd_Alias FOOBAR = /home/testing/bin/test.sh

## User Privilege Specification
root ALL=(ALL) ALL
%users ALL=(ALL) ALL
testing ALL=(ALL) NOPASSWD: FOOBAR

I used users group because I'm not in wheel.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#13 2014-07-14 18:42:20

rchipman
Member
Registered: 2014-07-14
Posts: 11

Re: [SOLVED] sudoers NOPASSWD problems

Cmnd_List seems to have no effect here.

The scripts I have been using do take options. However, I wrote a quick one with no options, and was still prompted for as password.
For reference, the script I used to test this:

#!/bin/bash
sudo pacman -Ss test

Offline

#14 2014-07-14 18:51:46

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] sudoers NOPASSWD problems

You are actually running 'sudo ./myscript.sh' and not just './myscript.sh' aren't you?

Last edited by Slithery (2014-07-14 18:57:50)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#15 2014-07-14 18:56:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,571
Website

Re: [SOLVED] sudoers NOPASSWD problems

There should be no "sudo" in that script - I think slithery might have nailed the problem.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#16 2014-07-14 19:03:00

rchipman
Member
Registered: 2014-07-14
Posts: 11

Re: [SOLVED] sudoers NOPASSWD problems

No....and that was the problem! First of all, thanks for all the help, and sorry that this was apparently a very simple mistake on my part.

But I would like to better understand why exactly sudo is necessary when executing the script. I realize now that the sudoers file is disabling password prompts for sudo calls to /home/rchipman/scripts/* as opposed to from scripts in that directory. But if sudo (as I understand it) is executing that script as root, why is sudo still necessary within the script itself? These kinds of nuances trip me up from time to time, and I would like to learn exactly why this is so so that I do not make the same mistakes going forward.

Offline

#17 2014-07-14 19:04:19

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] sudoers NOPASSWD problems

rchipman wrote:

But if sudo (as I understand it) is executing that script as root, why is sudo still necessary within the script itself?

As Trilby said, it isn't.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#18 2014-07-14 19:04:53

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,571
Website

Re: [SOLVED] sudoers NOPASSWD problems

rchipman wrote:

if sudo (as I understand it) is executing that script as root, why is sudo still necessary within the script itself

It shouldn't be - hence my previous post.  It really shouldn't do any harm either - but it can lead to confusion.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#19 2014-07-14 19:11:17

rchipman
Member
Registered: 2014-07-14
Posts: 11

Re: [SOLVED] sudoers NOPASSWD problems

Thanks!

Offline

Board footer

Powered by FluxBB