GNU/Linux: Controlling your screen brightness with media keys without a desktop environment

Step 1. Allowing unprivileged users to change brightness

Compile the following C program as changebr. You may have to change line 17 depending on your chipset (look in ls /sys/class/backlight/).

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <relative brightness>\n", argv[0]);
        return 1;
    } else {
        size_t curbrend;
        char curbr[17];
        int curbri, relnum;
        FILE *control;

        relnum = atoi(argv[1]);

        if ((control = fopen("/sys/class/backlight/intel_backlight/brightness", "r+")) == NULL) {
            return 2;

        curbrend = fread(curbr, sizeof(char), 16, control);
        curbr[curbrend] = '\0';
        curbri = atoi(curbr);
        sprintf(curbr, "%d", curbri + relnum);
        fwrite(curbr, sizeof(char), 17, control);
        return 0;

Place it in /usr/local/bin/ and chown root:root /usr/local/bin/changebr. Then make it setuid using chmod u+s /usr/local/bin/changebr. Switch to your normal account and check if you can change the brightness by running changebr -1000.

Step 2. Binding keys

Install Xbindkeys and put the following in your ~/.xbindkeysrc:

"changebr -1000"

"changebr 1000"

Reload the file using xbindkeys --poll-rc and your brightness keys should work.