If you need to disable the screen saver / screen auto switch off see here.

Auto Running The GUI

You can use the raspbian preferences via the GUI to cause the pi user to be auto logged in at boot up and the GUI automatically run.  However if you need to run with root privileges due to needing IO pin control (yes yes its not advised to run as root, but for many uses its fine where the security issues aren’t a concern) then set the raspbian preferences to boot to the command line.  Now open this file (the “sudo nano” assumes you are editing it from the command line):

sudo nano /etc/rc.local

Before the “exit 0” line in it add the following line:

#Auto run the GUI as root
sudo startx

Save it by pressing Ctrl+X, ” Y”, ENTER

Re-boot your RPi and it should automatically run the GUI as the root user.  

“No session for pid 696”

We get this message when using this method, the number will be random based on system.  It may well be because of using sudo startx.

You can use command “ps 696”  to see the process there is no session for, for us it was:

  902 ?        Sl     0:00 lxpolkit

lxpolkit is a “Policy authentication agent”.  There’s lots of google resources on no session for PID with lxpolkit but after a few hours of trying we didn’t manage to resolve.  Instead we started our application using a script with a delay before it runs so that it simply appears on top of the error message.  Bodge, but it works for us…

Setting An Application / Your Application To Automatically Run In The GUI

Raspbian Buster
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Raspbian Jesse

For the standard Pi user (if not using “sudo startx”):

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart

For the root Pi user (if running the GUI with “sudo startx”):

sudo nano /root/.config/lxsession/LXDE-pi/autostart

If the above gives a blank file, then there is not a per user file so edit the global one:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Continue here

This is the same file that is edited if you are disabling the screen saver, it causes things to be done when the GUI loads for a user. To run an application you simply add it on a line starting with a ‘@’ character.  A good way to test it works is to run one of the built in applications, say LX Terminal, by adding the following:


Use CTRL+X to save the file and then restart the GUI, you should see that LX Terminal is opened as soon as the GUI loads.

To run your own application then simply give the path to the executable file, which in this example is called “myapp”:

To run with a delay before launch

To run with a delay before your app launches, instead of adding the path to your app, provide a path to a script we will create:

@sh /home/pi/

Exit and save, then create the script file:

sudo nano /home/pi/

Insert the following into the file, setting the delay you want in seconds and the path to your app executable:

sleep 4

Exit and save, then finally make the script executable:

sudo chmod +x /home/pi/

That’s it, reboot and your app should launch after the delay period

Killing the application while running

Plug in a USB keyboard if necessary and press ALT+F4

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


  1. stephan schulz

    7 years ago

    for me on raspberry pi2 autostart was located here
    sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

    1. Arnold Chan

      2 years ago


  2. Darryl

    6 years ago

    Mine was at /etc/xdg/lxsession/LXDE/autostart

    1. Arnold Chan

      2 years ago

      thank you

  3. Some Guy Somewhere

    5 years ago

    How to start the application maximized, though?

    1. carlos cece

      2 years ago

      did you find out ?? i’m trying to launch thonny at te start up…

    2. Some Guy Somewhere

      2 years ago

      I did, but I don’t remember any more. It was not trivial, I had to change the command line I believe


Your email address will not be published.