Raspberry Pi is a great tool that helps you develop your computing skills and new technologies.
It has become widely popular among computer enthusiasts to help them improve their coding skills.
However, if you’re logged out of your account and can’t remember your password, you may be in trouble.
That’s because of the way passwords and usernames are stored, making them difficult to retrieve.
However, you’re not entirely out of luck, as there are different ways to help you log in.
Forgot Raspberry Pi Password (What To Do)
1. Reset The Password Via Commands
The passwords are stored in /etc/passwd on Linux.
However, if you’ve forgotten your password, there’s no way you can access this file and see your password.
Therefore, the best way to recover your data is to reset your password.
However, the methods for resetting a password differ depending on whether you can log in to your account or not.
For example, you can log in with your default username and password and reset your password if you haven’t changed them already.
If you have a user with sudo rights, you can log in with that user without providing a password.
All you need to do is run the following command:
sudo passwd
This command will prompt you to provide a new password without requiring your current one.
Another option would be to log in via the startup config.
Open a terminal window and type in sudo raspi-config.
This command will bring up a menu on which you can find the Change User Password option.
2. Eliminate The Need For A Password
Another workaround helps you change the settings so that Raspberry Pi doesn’t require you to provide a password.
Then you can enter the system and change your password via the command line.
This method requires unmounting the SD card and connecting it to a computer running on Linux, Windows, or macOS.
When you insert the SD card, you can see the file explorer on the window.
Look for /etc/passwd and edit it.
You should look for a line that starts with pi:x:1000:1000… and remove the x, leaving the two colons.
This edit will eliminate the need to provide a password.
Unmount the SD card, reinsert it into the Raspberry Pi and log in normally.
Then, use the passwd command to change your credentials.
3. Reset The Password By Removing The SD Card
This method helps you reset your password without contacting Raspberry Pi support.
Although it requires some hardware work, it’s pretty straightforward.
Please note that, like the above method, this method requires physical access to the Raspberry Pi and its SD card.
You also need a monitor, another PC with a microSD reader, and adapters for Pi Zero.
First, you need to remove Raspberry Pi’s SD card and insert it into your PC.
Before removing the microSD card, you need to turn off Raspberry Pi, which is impossible if it’s not connected to a monitor.
In that case, you should just unplug it.
Open the file explorer, open the memory card file, and look for a file named cmdline.txt in the root directory.
Open the file through one of your installed text editors and copy and paste the following command at the end of the text inside the file, making sure all of them are in one line:
init=/bin/sh
Save the file and unmount the SD card.
Now, insert it into the Raspberry Pi and turn on the device to see the blinking cursor in the single-user mode.
Remember that the Raspberry Pi should be connected to a monitor and a keyboard.
You’ll see a series of command lines scrolling quickly, and when it stops, you can start typing new commands.
If you’re using root credentials, you need to unmount and remount the root.
Type mount -o remount, rw / in the window, and
Type su in after the blinking cursor and enter the following command in the window:
passwd pi
Here, you’re prompted to enter your new password and press Enter twice.
Enter sync exec /sbin/init in the new window.
This command will restart Raspberry Pi while keeping your information inside the memory.
After the system reboots, turn it off, remove the SD card, and reinsert it into the computer.
Open the cmdline.txt again and delete the init = / bin / sh line to go back to normal settings.
If you want to change the password belonging to the pi user, you should type the following command:
Sudo passwd pi
Otherwise, you’ll just change the root password.
4. Resetting The Raspberry Pi Password For NOOBs
You can also reset the password via the NOOBs through steps different from those described above.
To do so:
- Boot the system in the recovery mode by pressing the Shift key while the system is booting up.
- Choose your Raspbian image and click on Edit config (e).
- Go to the cmdline.txt tab and type init-/bin/sh at the end of the command line.
- Press Ok to reboot the system.
When the system reboots, press Enter to see a line with #.
Here, you should type:
mount -o remount, rw /
passwd pi
Here, you’ll be prompted to enter your new password.
After entering the new password, enter sync:
Then, enter exec /sbin/init.
Now, repeat the process and remove the init=/bin/sh line.
Note: When you type the new password, it will be shown in *****.
Carefully watch for typos, or you won’t be able to use your new password.
How To Change Raspberry Pi’s Root Password
Changing the root password requires logging into your account.
If you’ve lost your password, you may want to go through the above methods.
To change the Pi’s root password, you need to log in as a root user upon boot up.
After logging into the root account, run the command line.
Access the account as a supervisor by entering sudo du and pressing Enter.
After typing in passwd root in the command line, you’ll receive system prompts to change the password.
Follow the instructions to finish the process.
How To Change Raspberry Pi’s Default Password
When you use the Raspberry Pi for the first time, it comes with a default username and password that you should change to boost your system’s security.
That’s because these credentials are universally used on all Raspberry devices by default, and if you don’t change them, you’ll leave your account vulnerable.
The new updates even ask you to change your password after the first boot.
First, log into your account using the default credentials and open a command window.
Type passwd in the command line and press Enter.
You should provide your current password and after verification, enter your new password.
Press Enter to change and apply it right away.
1. Change Default Root Username
The default username for Raspberry Pi is pi, and the default password is Raspberry.
It’s advisable to change your default user name and password via the Linux command, usermod.
However, it requires some settings enabled beforehand.
You should first log into your root user account since you can’t change these credentials through your Pi session.
Since you normally don’t log in with the root user, you’ll enter the Pi session upon boot up.
As a result, you should first disable this default setting and change the root password.
Otherwise, the system will show a message that your Pi username is currently in use.
Here’s how to disable your Pi session (you could skip this step for the Raspberry Pi Lite as it doesn’t have an auto-login):
Open the main menu and click on Preferences > Raspberry Pi Configuration > System > Auto login > Disable.
Now, you should enable SSH via the above route: Preferences > Raspberry Pi Configuration > Interfaces > Enable SSH.
The next step is to enable root to make another user with privileges that allow it to change the default username.
To do so:
Open a Pi session using SSH, a desktop terminal, or a Lite version session, and type the following command:
sudo passwd
This command will prompt you to set a new password for root.
You could also change the default username via SSH, for which root access to SSH should be enabled.
Here’s how to do it:
Enter this command to open the SSH configuration file:
sudo nano /etc/ssh/sshd_config
replace #PermitRootLogin prohibit-password with PermitRootLogin yes
After saving and exiting the file, restart SSH:
sudo service ssh restart
Note: After creating the new username, disable root access for security reasons.
Now, you can change the default username by first logging in with root by opening a session or using SSH, depending on the version you have installed.
Type usermod -l <new_user> pi in the session and replace “new_user” with your preferred username.
Then, it’s time to change the home directory’s name:
usermod -m -d /home/<new_user> <new_user>
And replace new_user with the new username.
Now, you can test the new password and username without rebooting the system to see if you’ve done the steps properly.
After entering your new account, it’s better to undo the changes you made with the auto-login and enable the SSH root access.
2. Changing Default Passwords For Other Usernames
You can use other users’ passwords on Pi provided that they have sudo permissions.
Enter the following command in the command line: passwd username.
You should replace “username” with the actual username you want to change the password for.
Type sudo passwd username, replacing “username” with the actual name.
You’ll need to provide the new password and confirm it one more time, and you’ll receive a message saying the password has been successfully changed.
How To Run Raspberry Pi Hardware Via Passwordless Sudo
The root user in a Linux system becomes a superuser that can access all parts and components of the server.
You can’t find these privileges with standard users because they can access only specific server parts and run limited commands.
By using the sudo command, you can give the standard user root access.
However, this access can be granted without requiring a password, which can be more convenient than providing a password every time you log in.
You can make a passwordless sudo account without compromising your security.
In addition, you’ll need this passwordless sudo account if you want to run specific hardware on Raspberry Pi, such as Simulink models.
The process of enabling passwordless sudo access is pretty straightforward, as follows:
Open the command-line interface and type in the following command:
sudo nano /etc/sudoers
You can simply enable passwordless sudo access by typing <user name> ALL=(ALL:ALL) NOPASSWD:ALL.
(Replace <username> with your intended username.)
Save changes and enter sudo reboot in the command line to restart Raspberry Pi and start it with the new settings.
You could also allow a specific user to use the passwordless sudo privileges only for specific commands.
Suppose you want to allow a user to run the fdisk-I command with passwordless sudo privileges.
In that case, you should type the following command in the command line:
nano /etc/sudoers
and add this line at the end of the file:
<username> ALL=(ALL:ALL) NOPASSWD: /sbin/fdisk -l
Creating A New Raspberry Pi User
You may decide to create another username and password for a new user on Raspberry Pi for different reasons.
The first reason is security concerns, as it’s not safe to use the default username and password.
Although many users prefer to use the same default username and password on different operating systems, such as root and pi, it’s not advisable for security reasons.
Creating another user can prevent hackers from attacking your systems via default credentials.
Another reason for creating new users is if you have multiple users working on the same system.
This way, you can assign each person a unique username and password with specific permissions.
You can create a new user via the adduser command by typing the following command:
Sudo adduser <username>
Again, the <username> section is replaced by the user’s name you want to set.
At this point, you’re prompted to enter other login information.
After answering the questions and pressing Enter, the new user will be created instantly with their own home folder located in /home/.
However, this user has no specific permissions, and you can grant them other permissions, such as passwordless sudo, as described above.
You could also add them to a group using the same adduser command.
All you need to do is enter the following command line:
sudo adduser <username> <group>
replacing the username and group with your intended names.
If you want to add the user to multiple groups, you can list the name of all groups instead of <group>.
Deleting A Raspberry User
You may want to delete some users from your Raspberry Pi for different reasons.
For example, you’ve added too many users and made things confusing for you, or you don’t need them anymore.
In such cases, you can delete these users through a simple command.
However, you need to take an extra step before deleting the user.
If you’ve already used these deleted accounts, you must have some home directory folders belonging to the users.
You may want to decide if you need to keep or delete these home files because deleting the account will remove these files, too.
You could copy them to the home directory of the new user through a simple command:
cp -R [SOURCE]/. [DESTINATION]
After copying the files, you can delete the use by running the following command:
sudo deluser –remove-home pi
This command will delete the user and its home directory.
However, you could still keep the home directory if you don’t have a backup of the folders.
You could just enter the following command to delete the user without its home directory:
sudo deluser pi
Adding A New Raspberry Pi Group
Raspberry Pi allows you to share it with different family members, enabling them to create their own files and home directories without having permission to delete or alter other members’ files.
You can easily add a new group with the addgroup command.
To do so, open a new command line by opening up a terminal window on the desktop or log in remotely over SSH.
Type in $ sudo addgroup robots and provide your password when required.
When the group is created, you’ll get a message confirming the group and giving you a GID value, which can be different across different devices.
Next, you should verify the group via the following command:
$ getent group robots
The system will verify the group by giving you the same GID value you received above.
After creating the group, you can add users via the steps described above.
simply explained. use full directions for the beginner