7

I changed the default username using usermod from pi, but since raspi-config assumes the user is "pi", I am now unable to have it automatically boot into the GUI. Is there another way to do this other than manually starting X?

7 Answers 7

9

You can manually modify the raspi-config script as follows. Let's presume we're using the username "bob".

sudo nano /usr/bin/raspi-config

then search for

do_boot_behaviour() {...}

Under that, there's a line where we will replace the "-u pi" with "-u bob", leaving the rest of the line unchanged:

if id -u pi > /dev/null 2>&1; then

Next edit the line:

sed /etc/lightdm/lightdm.conf -i -e "s/^#autologin-user=.*/autologin-user=pi/"

By changing autologin-user=pi to be autologin-user=bob

If you want a pretty menu and also error when it occurs, edit these lines:

whiptail --msgbox "The pi user has been removed, can't set up boot to desktop" 20 60 2
"Desktop" "Log in as user 'pi' at the graphical desktop" \

Again, replacing "pi" with "bob", or your username of choice.

Now the only thing left is enter raspi-config:

sudo raspi-config

Select the third option:

3 Enable Boot to Desktop/Scratch

And then select the second:

Desktop Log in as user 'bob' at the graphical desktop

This way the configuration files are written (crucial) and you are ready to automatically boot into the GUI

5

As of Raspberry Stretch you can simple login to youruser and call

sudo -s
raspi-config

and in the Boot Options Menu "B" under "B1/B2" you'll find .. automatically logged in as 'youruser' user will be available as an option. Select it and reboot.

1
  • 1
    Raspberry Pi 3 B+ on Raspbian Stretch here: I found the option as described and it worked as described. Except for the typo: the command is "raspi-config" which launches the ncurses configuration tool. And the options B1 and B2 both refer to auto-logging in to the desktop, one of which waits for the network to come up first. Either way my current, non-pi desktop user was explicitly named as the user that would be used for the autologin.
    – brokkr
    May 10, 2019 at 17:16
4

I had changed the pi user name and disabled the root account password, then followed direction in the previous answer including the suggested edit to this:

sed /etc/lightdm/lightdm.conf -i -e "s/^#autologin-user=.*/autologin-user=pi

but as Brandon indicated in his answer, I also had to edit the lightdm.conf file. Otherwise I got the graphical login prompt and an "x" placeholder above the login field where the Raspberry Pi logo would be. The auto login worked after the lightdm.conf edit.

2

In my case, I did not actually change (or delte) the default user "pi" user, I simply created a new user for myself and wanted to boot to that user by default. In that case, even after doing the above, I still ran into the issue of the system booting to the "pi" user by default. For some reason, the sed line was not actually updating lightdm.conf. So I simply edited lightdm.conf, which implicitly lists "pi" as the autologin-user, to my username. After that, it would successfully boot to my new user by default.

0

Emanuele, if the username pi is actualy deleted and/or replaced, like it was in my case, you also have to edit: "if id -u pi > /dev/null 2>&1; then" located 2 rows above, with the desired username instead of pi. This will avoid the username presence check.

0

I just want to add to the above that sometimes the auto-startx line can be found in /etc/rc.local especially when dealing with touchscreen images obtained from vendors. I once was trying to disable startx and did not think of it being here. The line will before exit 0. Just change the "pi" in that line to your new username and reboot!

0

I also need to modified /etc/lightdm/lightdm.conf, just need to remove the autologin-user=pi line in this configuration file, remaining from old configuration script, then apply new configurations again with the new raspi-config script.

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.