How to Change the Default Account Username and Password
By default your Raspberry Pi comes with an account 'pi' with the password 'raspberry'. For security reasons it's probably a good idea to change the password, but you may also wish to change the username as well. There are a couple of different ways to change the default username but I found the following method the easiest.
In order to change the username 'pi' we will have to log in a the root user since it's not possible to rename an account while your logged into it. To log in as root user first we have to enable it, to do so type the following command whilst logged in as the default pi user:
sudo passwd root
Choose a secure password for the root user. You can disable the root account later if you wish.
Now logout of the user pi using the command:
logout
And then logout back in as the user 'root' using the password you just created. Now we can rename the the default pi user name. The following method renames the user 'pi' to 'newname', replace this with whatever you want. Type the command:
usermod -l newname pi
Now the user name has been changed the user's home directory name should also be changed to
reflect the new login name:
usermod -m -d /home/newname newname
Now logout and login back in as newname. You can change the default password from raspberry to something more secure by typing following command and entering a new password when prompted:
passwd
If you wish you can disable the root user account again but first double check newname still has 'sudo' privileges. Check the following update command works:
sudo apt-get update
If it works then you can disable the root account by locking the password:
sudo passwd -l root
And that's it
4 comments
Paul Fretwell
This was very useful. I got it to work on Bullseye, you first have to turn off auto-login and set it to boot into console (in Raspberry Pi Configuration) before you logout via the desktop menu (choose Logout rather than Shutdown on the dialog when you go to power off the Pi). I did try logging in to the desktop as root, but the desktop does not load properly making it a challenge to get back to a terminal prompt.
A deep dive down some rabbit holes enabled me to learn what actually happens under the hood when you turn off auto-login, and how to automate it. So now I have written an Ansible script to automate the process of changing the default username, and to fix up config files that are left containing the old username (like the config which stops you being prompted to re-enter your password every time you want to run a sudo command).
This was very useful. I got it to work on Bullseye, you first have to turn off auto-login and set it to boot into console (in Raspberry Pi Configuration) before you logout via the desktop menu (choose Logout rather than Shutdown on the dialog when you go to power off the Pi). I did try logging in to the desktop as root, but the desktop does not load properly making it a challenge to get back to a terminal prompt.
A deep dive down some rabbit holes enabled me to learn what actually happens under the hood when you turn off auto-login, and how to automate it. So now I have written an Ansible script to automate the process of changing the default username, and to fix up config files that are left containing the old username (like the config which stops you being prompted to re-enter your password every time you want to run a sudo command).
Danny
this does not work on pi 4 (bullseye) – firstly, when typing in ‘logout, system responds with bash: logout: not login shell: use ’exit’ after this there are further errors/failures.
this does not work on pi 4 (bullseye) – firstly, when typing in ‘logout, system responds with bash: logout: not login shell: use ’exit’ after this there are further errors/failures.
Abdulrahman shuaibu
Good
Good
Jimoh
I want to change my surname
I want to change my surname