How to Change Default Username and Password on Raspberry Pi OS

Jinku Hu Feb 02, 2024
How to Change Default Username and Password on Raspberry Pi OS

This article will demonstrate how to change the default username and password on Raspberry Pi OS.

Change the Default Username on Raspberry Pi OS

Raspberry Pi OS comes with the default user pi, automatically created. It also has the default password - raspberry, which can be changed later, and on the initial boot, the system recommends the latter action.

Generally, it’s a good security measure to change the default password immediately, but modifying the pi user does not provide marginal improvement for your device security. However, if you still want to rename the default user, you can do it using the following instructions.

At first, you need to create a password for the disabled root user and log in with it into Raspberry Pi. Then we will be able to rename the pi user and move its home directory together with ownership of files.

The root account specifics on Raspberry Pi OS are covered in this article. In this case, we only have to execute the following command and type a new password when prompted:

sudo passwd root

Once the password is set successfully, the root account can log into the Raspberry Pi system.

However, you should log out from all currently active pi sessions, be it direct desktop environment, SSH connection, or other. Then log in using the root account and run the following command:

usermod -l new_username -d /home/new_username -m pi

It would be best to replace the new_username string with the desired user name in the previous command. Remember that the user names usually have some requirements, like it must contain only lowercase letters, dash or underscore characters, and it can end with the dollar sign.

This usermod command will rename the pi user with the provided name and move its home directory with corresponding file ownerships all in one. Although, they can break the command down into several parts.

Namely, the -l new_username part changes the user name, while -d /home/new_username -m is responsible for moving the existing pi home directory to the new location and adapting file ownerships.

Finally, you can reboot the system and log in with the new username with the existing password.

Change the Default Password on Raspberry Pi OS

Usually, this step is likely to be taken by users on the initial Raspberry Pi OS boot when the system explicitly recommends changing the default raspberry password. Nevertheless, you can utilize the following commands to modify the password or change them for specific users.

If you would like to change the password for the currently logged-in user, execute the following command:

passwd

It will display the input prompt to specify the new password string and then re-type it to confirm.

Alternatively, you might want to modify the password for other users. In this case, you should have sudo privileges or do it from the root account.

The following command could be used to change the password for the arbitrary user - bob from the pi user console:

sudo passwd bob
Author: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn Facebook

Related Article - Raspberry Pi

Related Article - Raspberry Pi Login