1

member

Easy 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

 

TV or monitor and HDMI cable
Keyboard and mouse

 

4. TV or monitor 1 pc

5. HDMI cable 1 pc

6. USB keyboard 1 pc

7. USB mouse 1 pc

Raspberry Pi
Monitor or TV
HDMI cable
USB keyboard
USB mouse
Power supply
8GB SD card

 

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

  1. Go to Terminal. Type the command: passwd
  2. Type the current password.
  3. Type the new password.
  4. Re-enter the new password.
  5. The password for user pi has been changed.
  6. 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.
  7. 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

  1. 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.
  2. 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.
  3. 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 
  4. 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
  5. 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.
  6. Remove Raspberry Pi's micro SD card (SD card) from your PC.
  7. Insert your Raspberry Pi's micro SD card (SD card)  to Raspberry Pi board.
  8. TV or PC monitor Display port (HDMI Port) must be connected to your Raspberry PI board HDMI Port.
  9. 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.
  10. Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
  11. 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 /
  12. You can change the password of your Raspberry Pi now. Type the command: su to log in as root (no password needed).
  13. 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):
  14. Once the password is changed, run these commands: sync
  15. exec /sbin/init
  16. 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.
  17. Remove the micro SD card (SD card) from Raspberry Pi.
  18. 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.
  19. 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. 
  20. Edit the file again  - remove the line init=/bin/sh and save it. 
  21. Remove Raspberry Pi's micro SD card (SD card) from your PC.
  22. Insert your Raspberry Pi's micro SD card (SD card)  to Raspberry Pi board.
  23. Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
  24. 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

  1. Go to Terminal. Type the command: sudo nano vipw 
  2. 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
  3. Reboot the Raspberry Pi by typing the command: sudo shutdown -r now (or sudo reboot)
  4. 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.
  5. Go to Terminal and type the command to change the root password: sudo passwd root
  6. Enter your chosen root password twice. Make sure you remember it! You have assigned the password for root account now.
  7. If it doesn't work check the ssh_config. Type the command in Terminal: sudo nano /etc/ssh/sshd_config
  8. Search for PermitRootLogin and change it to yes
  9. You can undo logging in as root again using this command : sudo passwd -l root
  10. 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: 
  11. su - pi -c \"fetchmail > /dev/null\"
  12. If you are developing programs which use the IO pin from the GUI you do not have to use the command in Terminalsudo startx to launch the GUI. Using the command in Terminal: sudo ./myprogram.a works fine.
  13. 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

  1. 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
  2. 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:
  3. Breaking the command down step by step we will investigate the options used: 
  4. sudo : this allows the command to run with administrative permissions; 
  5. useradd or adduser: this is the command to create new users and requires administrative permissions to run; 
  6. -m creates the home directory for the user at the same time the user is created; 
  7. 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;
  8. -G sudo: is used to add the user the the secondary group sudo
  9. The user account created can be viewed in the file /etc/passwd. Type the command in Terminaltail -1 /etc/passwd
  10. 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 Terminalsudo passwd alex
  11. 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
  12. 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.

  1. Type the command in Terminal to go from root user mode: exit or su pi (su your user name)
  2. Type the command in Terminal to delete just the user pi account: sudo deluser pi
  3. 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

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 08-04-2019
Viewed: 839 times