members
Raspberry basics: Project 01d Raspberry Pi How to change default password, set a root password and r
of Acoptex.com in Raspberry Pi 3
Raspberry basics: Project 01d
Project name: Raspberry Pi How to change default password, set a root password and recover a password
Tags: Raspberry, Raspberry PI, how to change password, how to set a root password and how to recover a password, Raspberry Pi 3 board, how to retrieve the lost password of Raspberry Pi, retrieve access, how to change root password
In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):
1.Raspberry PI 3 model B 1 pc
2. Micro SD card with NOOBS and SD card adapter 1 pc
3. Micro USB power supply (2 A 5V or 5V 3A) 1 pc
4. TV or monitor 1 pc
5. HDMI cable 1 pc
6. USB keyboard 1 pc
7. USB mouse 1 pc
General
We will learn how to change default user password, how to set a root password and how to recover a password, how to add additional user accounts, how to remove default pi user in Raspberry Pi.
The default Raspbian SD card image configures a default user account called pi with a password of raspberry. Every device using this image will therefore have the same username and password combination. This is great for quickly getting starting but isn’t very good practice from a security point of view.
1.How to change the default password for the user account pi?
To protect your Raspberry Pi from online threats, you should immediately change the default password.
Considering that we will have logged in as the user pi we can change our own password without the need of sudo.
Step by step procedure
- Go to Terminal. Type the command: passwd
- Type the current password.
- Type the new password.
- Re-enter the new password.
- The password for user pi has been changed.
- If you need to remove the password from a user account on your Raspberry Pi - use the command in Terminal: sudo passwd [USER] -d. Replace [USER] with user name.
- Another way to change the user password is raspi-config tool. Just type the command: sudo raspi-config . The raspi-config menu will start and it will now be running with the privileges in the system of the root user, the administrator account in Linux. You should see Change User Password as an option. Select this option and change your password as desired.
2. I have lost my password, is it possible to recover access to my Raspberry Pi?
Yes, it's possible to recover a forgotten or lost password on the Raspberry Pi. To be more exact, it is actually possible to change the lost password of your Raspberry Pi. We assume that you have Raspbian OS installed on your Raspberry PI board micro SD card (SD card).
Step by step procedure
- Turn off your Raspberry Pi through the Raspbian OS menu so you can disconnect Micro USB power supply to Raspberry PI board micro USB input and remove the micro SD card (SD card) safely.
- Insert Raspberry Pi's micro SD card (SD card) into your PC SD card reader (if you have micro SD card you may need to use SD card adapter) or use a SD card reader connected to your PC USB port.
- Open the file browser on your computer and go to the micro SD card (SD card) card. You will find the file named cmdline.txt on this memory card. This file should contain a line of text: dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
- Modify this file so that the Raspberry Pi starts on the bin/sh script, which will allow you to change the password of your Raspberry Pi. Just add the line to the end of the file: init=/bin/sh , you should have now dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait init=/bin/sh
- Save the file. It's very important that the text must be on the same line. Check that it's correct with different text editors.
- Remove Raspberry Pi's micro SD card (SD card) from your PC.
- Insert your Raspberry Pi's micro SD card (SD card) to Raspberry Pi board.
- TV or PC monitor Display port (HDMI Port) must be connected to your Raspberry PI board HDMI Port.
- Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1, etc), USB mouse and USB keyboard connected to Raspberry PI board USB ports.
- Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
- A series of command lines should scroll quickly. After a few tens of seconds, the screen will be completely frozen and you will be able to type text. We will now remount the drive in read-write mode. Type the command : mount -o remount, rw /
- You can change the password of your Raspberry Pi now. Type the command: su to log in as root (no password needed).
- Type the command: passwd pi and follow the steps on the screen (note that for security reasons the password may not appear when you type it):
- Once the password is changed, run these commands: sync
- exec /sbin/init
- The Raspberry will go out. Wait until the screen has completely frozen for at least 30 seconds and disconnect Micro USB power supply to Raspberry PI board micro USB input.
- Remove the micro SD card (SD card) from Raspberry Pi.
- Insert Raspberry Pi's micro SD card (SD card) into your PC SD card reader (if you have micro SD card you may need to use SD card adapter) or use a SD card reader connected to your PC USB port.
- Open the file browser on your computer and go to the micro SD card (SD card) card. You will find the file named cmdline.txt on this memory card.
- Edit the file again - remove the line init=/bin/sh and save it.
- Remove Raspberry Pi's micro SD card (SD card) from your PC.
- Insert your Raspberry Pi's micro SD card (SD card) to Raspberry Pi board.
- Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
- You should now be able to log in with the new password now.
3. How to change root password?
Using sudo will enable you to issue root commands, with which you can do or install anything. You don’t need to enter a password to use sudo as the root password is disabled by default.
If you really want to become root for any length of time, use the command in Terminal: sudo -i, then exit (or Ctrl-D) to go back to the pi account.
After logging in as user pi, using this command in Terminal give you root user privileges: sudo su it will log you in as root without the use of a password.
If you are annoyed at having to sudo every time and would like to be the root user, you must first set a password for the root account.
Step by step procedure
- Go to Terminal. Type the command: sudo nano vipw
- Change the line root:x:0:0:root:/root:/bin/bash - remove the x so the line will be root::0:0:root:/root:/bin/bash
- Reboot the Raspberry Pi by typing the command: sudo shutdown -r now (or sudo reboot)
- Use root as the username and press Enter button and you will have root access without a password (that’s why we removed the x above). After you change the root password you will be able to log in directly as root.
- Go to Terminal and type the command to change the root password: sudo passwd root
- Enter your chosen root password twice. Make sure you remember it! You have assigned the password for root account now.
- If it doesn't work check the ssh_config. Type the command in Terminal: sudo nano /etc/ssh/sshd_config
- Search for PermitRootLogin and change it to yes
- You can undo logging in as root again using this command : sudo passwd -l root
- If you are running as the root user (e.g. say within an app called with sudo because you are using the IO pins) you may want to make command lines calls as the standard pi user. You can change to a different user using su – USERNAME -c before the command and surrounding it with quotes:
- su - pi -c \"fetchmail > /dev/null\"
- If you are developing programs which use the IO pin from the GUI you do not have to use the command in Terminal: sudo startx to launch the GUI. Using the command in Terminal: sudo ./myprogram.a works fine.
- It's very important to know that the root user has complete access to every file, so you can really damage the Raspbian system if you don’t know exactly what you are doing. If you really destroy it, you will have to reinstall Raspbian on the SD card.
4. How to add additional user accounts
We can add other accounts to the Raspberry Pi. You can create new account instead of pi with and without administrative priviliges. The ability of the account pi to run the command sudo comes from the account being added to the group sudo.
Step by step procedure
- Go to Terminal. Let's create a new account for alex, to be administrator and and to be able to run sudo. Type this command in Terminal to add it to the group sudo: sudo useradd -m alex -G sudo
- If you are adding accounts for ordinary users then there is no need or desire to add them to the sudo group - type the command sudo useradd -m alex:
- Breaking the command down step by step we will investigate the options used:
- sudo : this allows the command to run with administrative permissions;
- useradd or adduser: this is the command to create new users and requires administrative permissions to run;
- -m creates the home directory for the user at the same time the user is created;
- alex : is the user account name to create. Usually this is lower-case as the login name as well as the password is case-sensitive in Linux;
- -G sudo: is used to add the user the the secondary group sudo
- The user account created can be viewed in the file /etc/passwd. Type the command in Terminal: tail -1 /etc/passwd
- This will display just the last line of the file and should display the new user account. The passwd file is accessible to all users to read so we do not have to use sudo. Useradd have created the user alex but not set the password for him. Let's set the user alex password by typing the command in Terminal: sudo passwd alex
- User passwords are stored in the file /etc/shadow. This is not readable by users so to list it we will need to use sudo, type the command: sudo tail -1 /etc/shadow
- This will list the new account with the new SHA 512 encrypted password.
5. How to remove the pi user
If you are doing this to improve security you might want to remove the pi user. You can do this by logging into the user pi account.
- Type the command in Terminal to go from root user mode: exit or su pi (su your user name)
- Type the command in Terminal to delete just the user pi account: sudo deluser pi
- If you want to remove the /home/pi directory as well, use the command in Terminal: sudo deluser -remove-home pi
Summary
We have learnt how to change default user password, how to set a root password and how to recover a password, how to add additional user accounts, how to remove default pi user in Raspberry Pi.
Library
- No libraries needed in this project
Sketch
- No sketches needed in this project
Other projects of Acoptex.com










jobs.viewed