Showing posts with label RaspberryPi. Show all posts
Showing posts with label RaspberryPi. Show all posts

Tuesday, 13 December 2016

Reset raspberry Pi forgotten password

Background

Well the background is bit embarrassing really :) To secure my raspberry Pi I set a very strong password and guess who forgot after a while :). Well I made my way back into the Pi but it was interesting. So will share this with you as well. Another constraint that I had is that I did not have my external keyboard with me so had to hack my way in. Will should you the same. However I will also list down a neater way in case you do have a keyboard.

NOTE : If you have not changed the password then it might still be raspberry. Try it. 



Without the keybaord

First and foremost you must know where passwords are stored. For Linux OS it is stored in /etc/shadow file. Ofcourse it's a one way hash and there is no way to reverse engineer it. But the file and its contents are important to us.

  • You should have another Linux distro with you. In this create a new user using command
    • useradd testuser
  • Now go to /etc/shadow file and you should see an entry corresponding to testuser. Something like -
    • testuser:!:16406:0:99999:7:::
  • Now remove the ! (or two) from between the first two colons, so it is testuser::16406.... This makes this a passwordless account.
  • Now change the current user to testuser using su command and change the password using passwd command -
    • su testuser
    • passwd
  • One you set the password you can go back to the /etc/shadow file and the line corresponding to testuser should now have a has password hash - something that most probably begins with $6
  • Copy this string and note it down.
  • Now take out your SD card from your Pi. Plug it into another Linux distro. Now on this open up the /etc/shadow file of pi and replace the hash that you might be having with the one you just noted above (You can do this for pi user).
  • And thats it you can use the same password you have for testuser to log into pi now. Try an ssh. You should be good.





Alternate route - the one with USB keyboard 

This is kind of non hacky route assuming you have a USB keyboard.
  • Remove SD card from your Pi. Plug it into some other Linux distro. 
  • In the boot partition you should find a file named cmdline.txt. 



  • Edit it to append 'init=/bin/sh' at the end. Before and after screenshots below -



  •  Save the file. Put the SD card back in Pi and boot up. Now Pi will boot up in single user mode.
  • When you get a cursor type in
    • passwd pi
  • and change the password of user pi. You can then do a normal startup using command -
    •  sync exec /sbin/init 
  • And that's it. Do not forget to remove the appended text that we put in cmdline.txt file. Remove it once you have successfully changed the password and your subsequent boots should be normal again.


Related Links

Sunday, 6 November 2016

How to set date and time in your Raspberry Pi

Background

If you have internet connection in your Raspberry Pi then all you need to do is set your timezone and you are all set. In this post we will see how.

How to set date and time in your Raspberry Pi

  • First open your raspi-config. To do that execute following command in your command line - 
    • sudo raspi-config
  • Once the config open select "Internationalization Options"
  • Next select "Change Timezone"

  • Next select your "Geographic Area"
  • Finally Select your "Time zone"
  • Save and Exit


And that's it your date and time should be set.

How to take screenshots in Raspberry Pi

How to take screenshots in Raspberry Pi

Raspberry Pi does not seem to have a default screenshot application like screenshot or snip. I will explain what worked for me. I am using scrot command line utility to take the screenshots.

To install scrot execute following command -
  • sudo apt-get install scrot

As you can see from screenshot above you can enter
  • scrot -s
and select the window you want to take screenshot of. If you want to take a complete screenshot with with some delay you can do -
  • sudo scrot -d5
You even have a -c option to show a countdown. You can see various options available with man command -
  • man scrot


PS : This whole post is written on my Raspberry Pi 3 Model B and have used scrot command for above screenshots :)

Related Links

Saturday, 5 November 2016

Getting statrted with Raspberry pi

Background

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries. More on Wiki.

So you can have your own computer with very little prior knowledge up and running in a very less time. And I am going to show you how.

Requirements

You need following things -
  • Raspberry pi (Link points to Raspberry pi 3 model b which I currently have)
  • A case to protect your pie (optional)
  • Monitor for external display
  • HDMI cable to connect your pi to the external display
  • A micro SD card to install your operating system
  • USB keyboard
  • USB mouse
  • micro usb charger to power your pi
  • Ethernet or lan cable if you want to connect your laptop to your pie (optional/you can use wifi)
This is how the pi looks like -

 Use cases for this are limitless. If you want to know what each component is and what does it do then refer the shot video I have created below -





Assemble and Deploy

  • Make sure you have all the components listed in the section above.
  • First thing you need to do is flash your micro SD card with some operating system. I am gong to use RASPBIAN but not directly. 
    • Go to https://www.raspberrypi.org/downloads/
    • Download NOOBS. It is New out of the box software. It will be a zip file.
    • Format your micro SD card
    • Copy the contents of the extracted zip file in your formatted micro sd card. Note content of the NOOBS folder must be copied not the top level directory. So there will be multiple files at top level.
    • Once you do that your micro sd card is all set up.
  • Next attach your micro SD card to your pi.
  • Connect USB keyboard and mouse to the pi.
  • Connect HDMI cable to PI and other end to your display.
  • Finally connect power supply. Once you connect power supply you should be able to see NOOBS getting loaded. It will promt you to install RASPBIAN which will take time to install.
  • Once the installation is complete your RASPBIAN will boot and you are all set to go.
Once it boots up it's same as any other computer you own. You can do all sorts of stuff.



Incase you missed in the youtube video above and wifi configuration point in deployment steps I would like to stress here that Raspberry pi 3 model b has inbuilt wifi and bluetooth module.

Connecting to your Pi


  • You can SSH into your machine.
  • SSH service is turned on bu default.


NOTE : Username is pi and password is raspberry.

  • You can do vnc too to remotely control your pi. Prior to that you need to enable it in the configuration. To do so go in
    • Menu -> Preferences -> Raspberry Pi configuration -> Interfaces
  • Here you will see lot of interfaces. Here SSH will already be enabled. You can enable vnc too.
  • Now from  your remote machine connect to your pi with vnc client.



References



  • You can open up raspi-config using command sudo raspi-config .You can use this to set varous thing like audi output to audio jack or hdmi.

Related Links


t> UA-39527780-1 back to top