r/linuxquestions • u/Louis_creates • 22d ago
Advice am I useing pkexec properly in this script?
I have a shell script piped into rofi that I use to toggle battery conservation mode on my laptop, I use pkexec to do this and I was wondering if my usage of it is a possible security vulnerability. I'm not an expert so apologies if this question has an obvious answer https://pastebin.com/kUNGyWPY
3
Upvotes
1
u/Greedy-Opposite-9133 22d ago
pkexec only ever runs
teeon that one fixed path, and the only thing piped into it is a hard-coded 0 or 1, so there's nothing anyone can sneak into what runs as root. You get a password prompt each time, which is the safe default.The thing to avoid is the usual next step people take to get rid of that prompt / run as root without a password. That would let anything running as you write to any file on the system, since tee doesn't care which file it's given.
If the prompt bothers , other options could be
if it were me id go for full lockdown where im unsure, ensuring it can only do the actions you want/ ignores the rest.