25

So I just installed raspbian jessie lite on my pi 2. But I can't get it to login automatically. I first tried with raspi-config, which didn't work. Then after googling a bit, I found a tutorial which I'm suppose to edit inittab but when I try to access it, it's empty.

3
  • 1
    If you select the right option in raspi-config it should work. Anything using inittab won't. Indeed most of the tutorials before mid 2015 (and many after) are for SysV and won't work. Some will actually interfere with normal operation.
    – Milliways
    Commented Jan 2, 2016 at 0:57
  • I have the same Rasbian Jessie on a Ras Pi 2. Try THIS (solution via raspberrypi.stackexchange) will probably help! Good luck
    – Alireza7am
    Commented Jan 2, 2016 at 2:07
  • @Milliways I have tried going into raspi-config, and changed the boot option to, console autologin but it doesn't work.
    – Yemto
    Commented Jan 2, 2016 at 8:31

4 Answers 4

42

I found a solution that uses raspi-config. I played around with it for a bit, and found something (NOTE: You may need to update raspi-config)

To enable Auto-login with raspi-config:

Run: sudo raspi-config
Choose option: 1 System Options
Choose option: S5 Boot / Auto Login
Choose option: B2 Console Autologin
Select Finish, and reboot the Raspberry Pi.

You should then be logged in automatically on every reboot. It's as easy as pi! :)

3
  • 1
    This should be the accepted answer. Worked perfectly.
    – slm
    Commented Jul 2, 2018 at 22:20
  • 2
    For me it was: 1 System Options -> S5 Boot / Auto Login -> B2 Console Autologin
    – nimig18
    Commented Sep 12, 2021 at 20:48
  • Yup! This is it. Came here from Google. Still working 2023.
    – dmanexe
    Commented Sep 21, 2023 at 17:16
12

I needed to know how to do this manually, not using raspi-config. I couldn't find anyone sharing the secret sauce. Thank Stallman for open source. Just read the source.

do_boot_behaviour() {
  if [ "$INTERACTIVE" = True ]; then
    BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Boot Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
      "B1 Console" "Text console, requiring user to login" \
      "B2 Console Autologin" "Text console, automatically logged in as '$USER' user" \
      "B3 Desktop" "Desktop GUI, requiring user to login" \
      "B4 Desktop Autologin" "Desktop GUI, automatically logged in as '$USER' user" \
      3>&1 1>&2 2>&3)
  else
    BOOTOPT=$1
    true
  fi
  if [ $? -eq 0 ]; then
    case "$BOOTOPT" in
      B1*)
        systemctl set-default multi-user.target
        ln -fs /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
        rm -f /etc/systemd/system/[email protected]/autologin.conf
        ;;
      B2*)
        systemctl set-default multi-user.target
        ln -fs /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
        cat > /etc/systemd/system/[email protected]/autologin.conf << EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
EOF
        ;;
      B3*)
        if [ -e /etc/init.d/lightdm ]; then
          systemctl set-default graphical.target
          ln -fs /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
          rm -f /etc/systemd/system/[email protected]/autologin.conf
          sed /etc/lightdm/lightdm.conf -i -e "s/^autologin-user=.*/#autologin-user=/"
          disable_raspi_config_at_boot
        else
          whiptail --msgbox "Do 'sudo apt-get install lightdm' to allow configuration of boot to desktop" 20 60 2
          return 1
        fi
        ;;
      B4*)
        if [ -e /etc/init.d/lightdm ]; then
          systemctl set-default graphical.target
          ln -fs /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
          cat > /etc/systemd/system/[email protected]/autologin.conf << EOF

What I learned from this is that my changes to /etc/lightdm/lightdm.conf were not affecting my autologin as expected because I was missing a file called /etc/systemd/system/[email protected]/autologin.conf

The critical missing step is this one:

cat > /etc/systemd/system/[email protected]/autologin.conf << EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
EOF

Which will be set to the username that raspi-config wants, not the one that you want. So you have to change the $USER in /etc/systemd/system/[email protected]/autologin.conf to match the username you are setting in the /etc/lightdm/lightdm.conf parameter autologin-user

4

First create a new service similar to [email protected]:

# cp /lib/systemd/system/[email protected] \
     /etc/systemd/system/[email protected] 

# ln -s /etc/systemd/system/[email protected] \
        /etc/systemd/system/getty.target.wants/[email protected]

then edit ExecStart, Restart and Alias values, like this:

...
ExecStart=-/sbin/mingetty --autologin USERNAME %I
Restart=no
...
Alias=getty.target.wants/[email protected]

and finally reload daemon and start the service:

systemctl daemon-reload systemctl start [email protected]

Note that if you exit tty8 session, you wont be able to use it until next reboot or manual start by systemctl, except if you leave Restart as ‘always’, but I highly recommend to avoid this according to security reasons.


source: fedoraproject.org/wiki

2
  • This solution didn't work at all.
    – piepi
    Commented Jan 1, 2017 at 3:20
  • 3
    it doesn't work if you blindly copy paste it, if that's what you mean
    – Havnar
    Commented Jan 3, 2017 at 12:45
4

The simplest way I have found using Raspbian, is to edit the raspi-config file. Do this by opening /etc/lightdm/lightdm.conf and setting the autologin-user= parameter.

Change: autologin-user=pi to autologin-user=username where username is your username.

1
  • 1
    Since when did /etc/lightdm/lightdm.con [sic] became "the raspi-config file"? Never mind that there's simply no such file in the first place on Raspbian lite. Commented Feb 7, 2020 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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