hyprwm / hypridle

Hyprland's idle daemon
BSD 3-Clause "New" or "Revised" License
320 stars 16 forks source link

Run a command elevated (sudo) ? #42

Closed dimitrisfasoulas closed 1 month ago

dimitrisfasoulas commented 3 months ago

Is it possible to invoke a script with sudo ?

I have a script that restarts a service. The script is added in sudoers: myusername ALL=(ALL) NOPASSWD: /home/myusername/script.sh and I'm able to invoke it with sudo without requiring password. But if I added to the listener like so:

# Screenlock
listener {
    # HYPRLOCK TIMEOUT
    timeout = 600
    # HYPRLOCK ONTIMEOUT
    on-timeout = hyprlock
    on-resume = sudo -u myusername /home/myusername/script.sh ; 
}

I get a prompt to provide sudo password.

vaxerski commented 3 months ago

echo [PASSWORD] | sudo -S <cmd>?

dimitrisfasoulas commented 3 months ago

aaah ... that might work, but I think I prefer typing the password each time than hardcoding it to a script :)

fjueic commented 2 months ago

aaah ... that might work, but I think I prefer typing the password each time than hardcoding it to a script :)

pkexec <cmd>

simonm commented 1 month ago

Hey dimitrisfasoulas!

Add the script or service to /etc/sudoers using visudo. Or add a config file to /etc/sudoers.d

Format like this:

yourusername ALL=(ALL) NOPASSWD: /home/yourusername/script.sh
dimitrisfasoulas commented 1 month ago

Thnx simonm but if you look at my original post I've already added the script to sudoers:

I have a script that restarts a service. The script is added in sudoers: myusername ALL=(ALL) NOPASSWD: /home/myusername/script.sh

simonm commented 1 week ago

Yes. My bad. Sorry about that

On Sat, Jun 8, 2024, 22:09 Dimitris Fasoulas @.***> wrote:

Thnx simonm but if you look at my original post I've already added the script to sudoers:

I have a script that restarts a service. The script is added in sudoers: myusername ALL=(ALL) NOPASSWD: /home/myusername/script.sh

— Reply to this email directly, view it on GitHub https://github.com/hyprwm/hypridle/issues/42#issuecomment-2156167547, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAARUZPUDN2A7H66B6C3EDZGNQIRAVCNFSM6AAAAABFXBWWUWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGE3DONJUG4 . You are receiving this because you commented.Message ID: @.***>