My keyboard backlight function keys don't seem to work, so I've written a script to change the keyboard brightness, which must be run as root. It is invoked like so...

sudo /usr/bin/local/backlight inc
sudo /usr/bin/local/backlight dec 

This works fine from the terminal, but it doesn't work as the command of a custom keyboard shortcut I created via keyboard settings.

Just guessing here, but might the issue be that the command, when invoked via the keyboard shortcut, is not actually running under my user, but as someone else, which wouldn't be in the sudoers file?

  • 1
    Do you normally need to type a password when you run a command via sudo? – RobertL Nov 3 '15 at 6:39

Gnome 3 uses an authorization mechanism called polkit so the right way to run that executable as root is via pkexec:

pkexec allows an authorized user to execute PROGRAM as another user. If username is not specified, then the program will be executed as the administrative super user, root.

To authorize the user in the active session to run that command as root you'll have to define a new action (as per the above spec) via a XML file under /usr/share/polkit-1/actions , let's call it org.fedora.pkexec.kbback.policy.

Content of /usr/share/polkit-1/actions/org.fedora.pkexec.kbback.policy:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"

  <action id="org.fedora.pkexec.kbback">
    <message>Authentication is required to Change Keyboard Backlight</message>
    <annotate key="org.freedesktop.policykit.exec.path">/usr/local/bin/backlight</annotate>


Next step is to assign the commands to your keyboard shortcuts via GNOME keyboard settings:

pkexec /usr/local/bin/backlight inc
pkexec /usr/local/bin/backlight dec 

(note: I used /usr/local/bin/backlight as the path for my executable, you'll have to alter the action file and the two commands if your executable path is different)

  • Did this, but the shortcut still doesn't seem to function. I can, however, run the command from the terminal, and it works. Good news though, I just installed a system update, and the back-light function keys began to work. – Josiah Oct 7 '14 at 5:06

I think you need to use gksudo in this case. I quote from the gksudo(1) man page:

gksu is a frontend to su and gksudo is a frontend to sudo. Their pri‐ mary purpose is to run graphical commands that need root without the need to run an X terminal emulator and using su directly

So it would seem that the issue here is that the commands launched by the keyboard shortcut do not have a (pseudo) terminal device hooked up to them, which causes sudo to fail and gksudo should be used instead.

  • Dang, looks like gksudo doesn't exist in Fedora (Fedora 20) anyways. I'll look around for an alternative. – Josiah Oct 2 '14 at 6:54
  • @Josiah There seems to be an alternative called Beesu but I'm not sure if it's part of the "official" distribution. Use at your own risk and please don't deploy in a production multi-user environment until you're sure it's safe. – Joseph R. Oct 2 '14 at 7:00
  • @Josiah Another alternative may be if your keyboard shortcut can be configured to "Run in a terminal". Have you tried that? – Joseph R. Oct 2 '14 at 7:01
  • I remember that option in gnome2, but I don't see it here. – Josiah Oct 8 '14 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.