hypridle icon indicating copy to clipboard operation
hypridle copied to clipboard

Run a command elevated (sudo) ?

Open dimitrisfasoulas opened this issue 1 year ago • 3 comments

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.

dimitrisfasoulas avatar Apr 04 '24 11:04 dimitrisfasoulas

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

vaxerski avatar Apr 04 '24 15:04 vaxerski

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

dimitrisfasoulas avatar Apr 04 '24 20:04 dimitrisfasoulas

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

pkexec <cmd>

fjueic avatar Apr 11 '24 05:04 fjueic

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

simonm avatar Jun 08 '24 12:06 simonm

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

dimitrisfasoulas avatar Jun 08 '24 20:06 dimitrisfasoulas

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: @.***>

simonm avatar Jun 29 '24 18:06 simonm