Change Default Raspberry Pi OS Username/Password
By default, new installations of Raspberry Pi OS/Raspbian provide a username of pi
with a password of raspberrypi
. What if we want to change the username or password?
Change Password
Changing the password is straightforward – login to the Raspberry Pi (using ssh or however you typically login). At the command prompt enter the command:passwd
And enter the new password when prompted.
Change Username
Changing the username is a bit more complex. First, login to the Raspberry Pi (using ssh or however you typically login).
We will need to login as root which is disabled by default, so at the command prompt create a password for the root login:sudo passwd root
And enter a new password for the root account when prompted.
If you are connecting to the Pi using ssh then you will need to allow root login to ssh by editing the ssh config file:sudo nano /etc/ssh/sshd_config
and adding the line:PermitRootLogin yes
then save your change by pressing the “control” and “x” keys and pressing the “y” key when prompted.
Restart the ssh daemon:sudo systemctl restart ssh.service
Next, logout of Raspbian:logout
Now login to Raspbian with username root
and the password you created for root in the above step.
At the command prompt enter the following to change the username from pi
to whatever you want (it cannot be root). In this example we are using a username of myname
:usermod -l myname pi
We also need to update the user home directory to have the new username, so enter the following:usermod -m -d /home/myname myname
And we will also change the default group called pi to our new username:sudo groupmod --new-name myname pi
Next, logout:logout
And now login using your new username.
At the command prompt verify that your modified account has elevated user privileges by entering a command that requires sudo, eg:sudo apt-get update
which will prompt you for your new username password and execute after you enter the password.
If your account is working correctly, then disable the root login for security purposes:sudo passwd -l root
Disable root login from ssh:sudo nano /etc/ssh/sshd_config
and remove the line you added:PermitRootLogin yes
then save your change by pressing the “control” and “x” keys and pressing the “y” key when prompted.
Restart the ssh daemon:sudo systemctl restart ssh.service
You should be now able to log in and out using the new username.