[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Unable to execute a script without asking for sudo password, even after editing sudoers file.



Hi

On Sun, Mar 30, 2014 at 04:44:13PM +0530, Anubhav Yadav wrote:
> Hi I have created a script called i3exit that allows me to suspend or
> hibernate my laptop without having to exit my i3wm thus allowing me to
> save my  work.
> 
> Here are the contents of my script:
> 
> #!/bin/sh
> lock() {
>     i3lock
> }
> 
> case "$1" in
>     lock)
>         i3lock -d -i /home/neo1691/.i3/i3lock_screen.png -n
>         ;;
>     logout)
>         i3-msg exit
>         ;;
>     suspend)
>         sudo pm-suspend
>         ;;
>     hibernate)
>         sudo pm-hibernate
>         ;;
>     reboot)
>         sudo reboot
>         ;;
>     shutdown)
>         sudo halt
>         ;;
>     *)
>         echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
>         exit 2
> esac
> 
> exit 0
> 
> This script is stored in home/neo1691/bin/ directory and the directory
> is added in the PATH variable by adding   'export
> PATH=${PATH}:/home/neo1691/bin' in my .~/.bashrc file
> 
> I used sudo visudo to edit the /etc/sudoers file and added this line at the end:
>  neo1691 ALL=(ALL) ALL, NOPASSWD: /home/neo1691/bin/i3exit
> 
> After a restart when I run 'i3exit suspend' from my terminal, I am
> still asked for my password.

That is your problem: You have configured sudo to allow you to run
i3exit as root.

But you don't. You run i3exit as yourself (without sudo), and IT then
uses "sudo pm-suspend" (and others).

Two possible ways forward:

- Call it using "sudo i3exit" and remove the calls to sudo from inside
  the script

- Call it as yourself (= just "i3exit") and give yourself the
  privileges to run "reboot", "halt" and others as sudo.

Hope this helps
-- 
Karl E. Jorgensen


Reply to: