Change you raspberry pi default username

By | October 7, 2024

First see if you can see your pi using

ping raspberrypi.local

If you get a ping back your raspberry pi is communicating.

Then ssh into your pi using

ssh pi@raspberrypi.local  

You might get an error so just generate another key using.

ssh-keygen -R raspberrypi.local

Now you should be able to login

ssh pi@raspberrypi.local

Now lets create another user called “tempname”. It will be deleted later.

sudo adduser tempname

Add the tempname user to the sudo group. We need this so we have root permissions.

sudo adduser tempname sudo

Auto login is enabled which will use the pi user by default. You need login into the “tempname” account instead. The easiest way to do this it to use the GUI.

Configure the pi to auto login setting: “Desktop GUI, requiring user to login”. Do this using sudo raspi-config

Note: This method requires a monitor and keyboard to do this.

sudo raspi-config

Select “System Options”. Then scroll down to

Select “Boot /. Auto Login”.

Select “Desktop GUI, requiring user to login”. Save and reboot pi.

When the pi boots a login screen will display select the “tempname” account.

Now you can change the pi name using the following.

sudo usermod -l newname pi

And then change the home directory name to reflect the new login name.

sudo usermod -m -d /home/newname newname

Reboot again and this time login as the “newname” account. Then delete the “tempname” user.

sudo deluser -remove-home tempname

Now using sudo raspi-config change the auto login to: “Desktop Autologin Desktop GUI, automatically logged in as “newname”… and reboot the pi.

The pi will now automatically login as the “newname” user.

One last step we need to remove the “pi” user from any other areas. Check for Existing X Settings Linked to Old User: There might be X-related files in the /home/newname directory with references to the old user or permissions issues. Specifically, check:

ls -la /home/newname/.Xauthority

Create group is one does not exist:

sudo groupadd newname

Ensure the ownership is correct:

sudo chown newname:newname /home/newname/.Xauthority

You are now finished, have fun!