How To Change The Password On A Raspberry Pi


Password Header

The other day I realized that I had no idea how to change my Raspberry Pi’s password. I was setting up a small data collection project that had multiple users so I needed to make sure that someone wouldn’t log into the primary Pi username so I had to change the password. Despite having spent a fair number of hours working with the Raspberry Pi, I had never changed a password before. After doing some research here’s what I found.

How do you change the password on a Raspberry Pi? If you are already logged the default user, the “sudo raspi-config” into the command line and select the second option. If you are not the default user you can use the “passwd” command to change your password. If you have forgotten the root password, you can change it by editing the command.txt file by removing the SD card and editing it in a PC.

How To Change Your Password

There are 2 ways to change the Password on your Raspberry Pi if you are already logged in. Which one you choose depends on if you are the default user or not.

You Are The Default User

If you are the default user, you can change your username quite easily. First, open the command line and type sudo raspi-config and press Enter.

This will open the Raspberry Pi Configuration Tool. Select the second option Change User Password and follow the prompts. That’s all there is to it.

You Are Not The Default User

If you are not the default user you have nothing to fear. The process to change your password is still extremely simple. Open the command line, type passwd, and press Enter. You will be asked for your current password to continue. You will then be prompted to enter your new password and confirm it.

Note: No characters will be displayed while you are entering passwords.

After you have re-entered your new password you should receive a confirmation in the command line. Your new password is now active.

What If You Forgot Your Password

If you are not the default user, you can always ask a different user with sudo access to reset your password using the instructions above. If, however, you are using the default account, then the steps are a little more complicated.

The first thing you will need to do to reset the default password on your Raspberry Pi is to turn it off and remove the SD card. Once you have the card, insert it into a computer with a card reader. You will need to access the files on the card and look for a file name cmdline.txt. The file should contain a line of code that looks like this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

You will need to get your Raspberry Pi to start on the bin/sh script. This will allow you to edit the password of your Raspberry Pi without having to enter to current password in first. To do this, add the following code to the end of the cmdline.txt file. Be sure to add the code on the same line as the rest of the file.

init=/bin/sh

Once you have modified the file, save it and remove the SD card from you computer. It’s time to change that password.

Insert the SD card back into your Raspberry Pi and boot it up. You should see some command lines flashing across the screen for a few seconds. Once your screen stops changing it will be time to mount your root folder. You can do this by entering to following into the command line.

mount -o remount, rw /

Next, you will actually change the password. Do this by using the passwd command by typing:

passwd pi

Once you have entered this, you can go ahead and type in your new password. You may not see any characters show up on the screen as you type, this is okay. Finally, you will need to run the following two commands:

sync
exec /sbin/init

Your Raspberry Pi should turn off for a bit. After you see no activity for 30 seconds, you can turn off your Raspberry Pi.

The very last step is to take the SD card out of your Raspberry Pi and delete the text you added to the cmdline.txt file. Once you have completed this step you should be good to go!

How To Change A Different User’s Password

If you are a sudoer you have the ability to change a different user’s password with the passwd command. What you will need to do is open the command line, type sudo passwd username replacing username with the actual username of the account. This will give you the option to change the user’s password along with some other optins. If you want to leave a setting unchanged, just press Enter.

When Should You Change Your Password

You don’t always need to change the password on your Raspberry Pi, it really depends on what it is being used for. If you are using it to build a robot, make a smart TV, or something else that doesn’t require the information on it to be secure, you are usually safe leaving the default username and password of pi and raspberry.

If you are making something that is going to be accessed by several users or the public, then it may be worth changing your password and possibly even creating multiple users.

How To Create A New User

If your Raspberry Pi needs multiple users then you will need to create some new users. Creating a new user is quite easy using the command line. Simply use the adduser command by typing sudo adduser username replacing username with the name you want for the new user. You will be prompted to set the password for your new user as well. If you don’t want the user to need a password, simply press Enter.

This new user will not be a member of several security groups and you will need to add them to those groups if that is needed.

How To Delete A User

If you run into a situation where you need to delete a user, you can use the deluser command. Simply type sudo deluser username into the command line and the user will be deleted. If you want to remove the user’s home folder then type sudo deluser -r username instead. This will delete the user and their home folder as well.

Related Questions

What does sudo mean?

Sudo is a term that allows users to run commands as a “super user” It is actually an acronym for superuser do. This command increases the security privileges of the user when they are running a specific command.

What is the default Raspberry Pi username and password?

When setting up your Raspberry Pi for the first time, the default username is pi and the default password is raspberry. This shouldn’t be too hard to remember given the name of the board.

Recent Content