You are not logged in.

#1 2022-07-22 17:30:14

Niram96
Member
Registered: 2021-09-08
Posts: 13

[Solved] Change CPU frequency with cpupower without password

Hi smile

I want to change the CPU frequency between powersave, ondemand and performance profils with shortcuts without enter my password. I want to change the frequency depending of my laptop is running on battery or is plugged ; Or depending my laptop's battery level.
I tried to make shortcuts and added exceptions with "NOPASSWD" in /etc/sudoers file but it doesn't work.

I tried 2 methods :

1) /etc/sudoers :
user ALL=(ALL) ALL
user ALL=(ALL) NOPASSWD: /usr/bin/sudo /usr/bin/cpupower frequency-set -g performance

2) I made a script named "cpupower-p" which contains :
"sudo cpupower frequency-set -g performance"

/etc/sudoers :
user ALL=(ALL) ALL
user ALL=(ALL) NOPASSWD: /usr/bin/sudo /home/user/cpupower-p

Every time I launched the command in the terminal, it asks me my password. When I tap the shortcut nothing happen and when I not write "sudo", it tells me :
"Subcommand frequency-set needs root privileges"

For now the only solutions I have to change the frequency without password are:
- Change it with cpupower-gui, that's what I use now.
- Disable the password's demands with "user ALL=(ALL) NOPASSWD: ALL" but I don't want to do that. I just want an exception for the CPU frequency.

If you can help me, I'll appreciate it. smile

Last edited by Niram96 (2022-07-28 19:52:12)


*            *  *  *     *      *     *      *     *      *
*               *         * *   *     *      *         *
*               *         *  *  *     *      *         *
*  *  *     *  *  *     *      *     *  *  *     *       *

Offline

#2 2022-07-26 16:38:20

Bevan
Member
Registered: 2009-09-08
Posts: 104

Re: [Solved] Change CPU frequency with cpupower without password

Hi,

your entries in the sudoers file should not include /usr/bin/sudo but just the command that is called via sudo, i.e.:

user ALL=(ALL) NOPASSWD: /usr/bin/cpupower frequency-set -g performance
user ALL=(ALL) NOPASSWD: /home/user/cpupower-p

Offline

#3 2022-07-28 19:51:30

Niram96
Member
Registered: 2021-09-08
Posts: 13

Re: [Solved] Change CPU frequency with cpupower without password

Hi,

Lol I don't understand, I previously tried without sudo and it didn't work. lol
I probably used a wrong command.

Thank you ! It works fine now. smile


*            *  *  *     *      *     *      *     *      *
*               *         * *   *     *      *         *
*               *         *  *  *     *      *         *
*  *  *     *  *  *     *      *     *  *  *     *       *

Offline

Board footer

Powered by FluxBB