Auto Login and Auto Start in Raspberry Pi

Posted on 11th May 2013

Like most people you might have bought the Raspberry Pi to build your own appliance for home or office. The next thing you would do is setup the Raspberry Pi, connect your peripherals and install or develop the necessary software.

What you would expect to see at the end of your project is to power on the appliance and it should show you all the magic that you wanted to see.

The spoiler comes when the Pi boots to the login prompt and wait for you to enter the username and password. This article explains how to automate some of the tasks in a Raspberry Pi.

Auto Login

How to automatically login to Raspberry Pi text console as pi user.

Read this article Raspbian Jessie/Stretch AutoLogin to Console for configuring auto login on the latest Raspbian operating system.

Step 1: Open a terminal session and edit inittab file.

sudo nano /etc/inittab

Step 2: Disable the getty program.
Navigate to the following line in inittab
1:2345:respawn:/sbin/getty 115200 tty1

And add a # at the beginning of the line to comment it out
#1:2345:respawn:/sbin/getty 115200 tty1

Step 3: Add login program to inittab.
Add the following line just below the commented line1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
This will run the login program with pi user and without any authentication

Step 4: Save and Exit.
Press Ctrl+X to exit nano editor followed by Y to save the file and then press Enter to confirm the filename.

Reboot the pi and it will boot straight on to the shell prompt pi@raspberrypi without prompting you to enter username or password. But this isn't enough; you need your Pi to automatically run some command or a script. which is explained in the next section.

Run a Script after login

How to automatically run a script after login.
Step 1: Open a terminal session and edit the file /etc/profile
sudo nano /etc/profile
Step 2: Add the following line to the end of the file
. /home/pi/
replace the script name and path with correct name and path of your start-up script.
Step 3: Save and Exit
Press Ctrl+X to exit nano editor followed by Y to save the file.

Auto Start the Desktop (LXDE)

How to automatically boot to desktop

Step 1: Open a terminal session and run raspi-config

sudo raspi-config

Step 2: Select Enable Boot to Desktop/Scratch from the menu and press Enter

Step 3: Select Desktop Login as user pi at the Graphical Desktop.

Step 4: Select <Finish> and Enter, then select <Yes> to reboot.

Pi will now boot straight to the Desktop.

Post a comment


Hola | September 1, 2017 3:18 PM |

nobody are in "sudo nano /etc/inittab" It's notting . what should i do?

Aron | August 17, 2017 7:03 AM |

Hello I've got problems with these instructions after i reboot. Run a Script after login How to automatically run a script after login. Step 1: Open a terminal session and edit the file /etc/profile sudo nano /etc/profile Step 2: Add the following line to the end of the file . /home/pi/ replace the script name and path with correct name and path of your start-up script.

Itsik | August 4, 2016 5:15 AM |

inittab no longer exists in raspbian jessie

ptnorbeck | May 26, 2016 6:53 AM |

I created my own user account and completely removed the 'pi' user account. Since now raspi-config refuses to run without a 'pi' user, I had to manually edit the config file /etc/lightdm/lightdm.conf scroll down and change: #autologin-user= to: autologin-user=username or whatever account you use.

lotf | May 9, 2016 10:22 AM |

how to run the program as soon as I put in alimentaion raspberry pi

Burnie | February 6, 2016 4:03 PM |

auto-login worked very well when i rebooted for the first time. however, after i shut down and powered off/on there is no more output on HDMI. (B+) any idea?

Tarpie | October 11, 2015 5:11 PM |

I deleted user "pi" and i like to autologin and autostart lxde with another user. How to config that?

Tarpie | October 11, 2015 5:11 PM |

I deleted user pi and i would like to achieve auto start desktop. How to configure?

sara | October 11, 2015 5:11 PM |


sialee | October 6, 2015 8:59 AM |

my raspberry don't have inittab file help

s1pierro | August 31, 2015 7:19 PM |

Thanks, very helpful.

Marcio | August 29, 2015 3:54 PM |

for SYSTEMD autologin: (inittab not working on new distro) 1 - Create the directory: sudo mkdir /etc/systemd/system/getty@tty1.service.d 2 - Create file: sudo nano /etc/systemd/system/getty@tty1.service.d/autologin.conf 3 - Insert: [Service]
ExecStart=-/sbin/agetty --autologin --noclear %I 38400 linux 4 - Save and Quit 5 - Reboot Worked here

Scot | July 14, 2015 9:08 PM |

My raspbian system is running systemd so the inittab edit doesn't work. How do I do this in a systemd system? Thanks

DerPixelPlayer | July 6, 2015 8:37 PM |

No it's not, cause if you autologin, everyone has root permissions if he hacked your raspberry pi even if you autologin into pi user!

Erik Olson | July 1, 2015 6:43 AM |

Is this practice safe? As in does this create a security vulnerability?

Usman | June 29, 2015 6:12 PM |

Its ok, I got it working a few days ago.

Usman | June 25, 2015 6:17 PM |

I was looking at your tutorial which is perfect for my project, thank you. It allows me to log in straight away and run a bash script from start. However I need to login from the start as root to use the bash script to its full extent. Do you have any idea how to do this? Thank you.

Toaster guy | June 11, 2015 10:41 PM |

Works great with my print server (cups) first auto logs in next automatically starts cups and raspberry pi is plugged in extension lead so that both turn on

David | June 3, 2015 9:48 PM |

To solve the "INIT: Id "1" respawning too fast: disabled for 5 minutes" errors, make sure the line 1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1 is correct. If you have the path /sbin/login (because of lazy editing) it will not work and you will receive this error. If everything is done correctly this works on Raspberry Pi model B+

Zen'ski | June 3, 2015 9:47 PM |

works fine from first correctly written line thanks

jokre | May 9, 2015 10:22 AM |

Getting the "INIT: Id "1" respawning too fast: disabled for 5 minutes" error at login can be avoided by getting rid of the dot (.) in the beginning of the shell script autostart row in the /etc/profile example above. Just starting the row with the absolute or relative path to the script (and no dot+space) will work and will not produce the respawning error. Another alternative is to use .bashrc

Bruce | May 9, 2015 10:22 AM |

Worked perfect on my Raspberry 2thank you

HilljerkScribe | April 27, 2015 8:59 PM |

Cntl+Alt+F2 at the respawn too fast got me to a command promt so I could re-edit the line. Undo the edit, re-boot and I was good to go! Hope this helps. Total noob to linux and Pi. Google everything so far to learn. Still want to know how to do this 'no username/password/run a script' thing.

niklas | April 11, 2015 12:12 AM |

Joe Pi User is right!! I had the same problem with B+ and would not recommend this method.

PaulSutton | April 4, 2015 2:46 PM |

Excellent article, may I suggst that you could do cd /etc cp inittab inittab.bak then edit init4921818766188776itb as above, that way you have a back up, if there is a problem, put card in to a Linux box, mount, and rename the backup. I would assume this would work fine. Paul

Joe Pi User | March 10, 2015 9:15 PM |

BEWARE this caused boot errors in my Raspberry B+. Couldn't get it to complete the boot - just got "INIT: Id "1" respawning too fast: disabled for 5 minutes" errors. Had to use a fresh Raspbian install on 2nd SD card, mount the old card via USB, then return it's /etc/inittab to original config. Burned 3 hours of my time. I'll find a different way to auto-login.

KOUSTA | March 10, 2015 9:13 PM |

Thanks dude it was very helpful

Someone | February 9, 2015 9:37 PM |

Can't I change it back to displaying the login?

RasPi4XMas | January 3, 2015 10:41 AM |

Hi all, This does not work on my Pi. All changes in inittab have been saved and are still ther after a reboot, but I still need to login manually. I have the same problem with startup programs and changes made in config.txt. Any changes I make in config or inittab are saved but have no effect on startup. I'm using Noobs: is it possible that Noobs overrides my startup parameters with its own ?

Andy | November 29, 2014 12:46 PM |

Thanks for the article, worked great. One note for other people trying the auto login, when I edit inittab the line of data doesn't show exactly as you have here with 115200. Mine had --noclear 38400 but as this was removed with the # i guess it makes no difference.

Otto Echeverri | October 2, 2014 9:58 AM |

Thank you for your help but /sbin/login fails because there is no "login" file in the /bin directory

terry | July 16, 2014 2:07 PM |

cannot config with sudo rasp-config

sagar choudhary | June 25, 2014 10:38 PM |

works great man. thanks a lot

Matt | June 14, 2014 12:27 AM |


BP | February 10, 2014 5:44 PM |

remove the scratch entry from the file /etc/xdg/lxsession/LXDE/autostart

David Yung | February 10, 2014 5:37 PM |

I accidentally auto booted to Scratch how do i boot back to my Raspberry pi os? Thanks