Auto Login and Auto Start in Raspberry Pi | Date Published: 2013-05-11 08:17:00

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.

Open Tech Guides |