Installing Raspbian on the Raspberry Pi & using SSH and VNC to remotely connect to the Raspberry Pi

In this blog entry the installation of the Raspbian Wheezy Linux Distribution on an SD Card will be demonstrated. The SD card will then be inserted into the Raspberry Pi board and  some initial configurations will be performed. Accessing the Raspbian Linux OS remotely over both SSH and VNC will also be demonstrated.

For starters you’ll need an SD card. The minimum acceptable size card is 2GB. However I highly recommend that you use a 4GB SD card as a minimum. An 8GB SD card will give you a decent amount of space, especially if you want to load many files and install many programs on your Raspberry Pi board. So I will be using an 8GB Card.

Installing the Raspbian Image on your SD Card

Start up VMWare Player  and then the KubuntuVM guest machine that was created in the first tutorial.

  • Plug in the unformatted SD Card into the USB reader. Currently the USB SD card reader is attached to the host (Windows 7) operating system (OS). To disconnect it from the host OS and connect it to the Guest OS, click on the “Player” menu and then go to “Removable Devices” and then select your USB SD Card reader which should show up as “XXXX Mass storage Device”. Then click on “Disconnect (Connect to Host)”. Within a few seconds the SD Card will be mounted in the Kubuntu OS and you should be able to see it via the Dolphin File Manager.
  • The Next step is to download the Raspbian Wheezy Linux distribution image from this page. You can directly download the zip file from the site. Though torrenting the file will result in a faster download. Also take note of SHA-1 hash string and the username (pi) and password (raspberry) listed on the page.
  • Once you download the compressed image, open a console window and navigate to the folder containing the image. If you are using the default Kubuntu web browser; “rekonq”, the image should be in the “/home/halherta/Documents” directory so you would have to type at the command prompt “cd ~/Documents“.
  • Once there, type the following command: “sha1sum 20xx-xx-xx-wheezy-raspbian.zip“. Where the ‘x’s should represent the image version. After a few seconds, a long and seemingly random string will be printed in the console window. Compare this resultant string with the one on the Raspbian Wheezy Download Page. If the Raspbian image was downloaded correctly and is not a corrupt file then both strings (hash codes) should be identical.
  • Now that you verified the file integrity of the compressed Raspbian image, uncompress it using the following command:  “unzip 20xx-xx-xx-wheezy-raspbian.zip” After the decompression process completes, you should end up with another file called “20xx-xx-xx-wheezy-raspbian.img”.
  • In order to find out the name of device of your SD card type the following command “df -h”
  • If you only see a single drive e.g. “/dev/sda” chances are that this drive is your primary drive. You can easily tell by looking at the printed filesystem size. This also means that the OS did not mount the SD card for you automatically.

Figure 1. Detecting all mounted partitions using “df -h”

In this case, open the dolphin file manager from the KDE start menu and double click on SD card (removable media) icon in the Dolphin File Manager (Figure 2).

Figure 2. Double Click on the SD card icon in the Dolphin File Manager

  • This should get the SD card mounted. Now go back to the command line and type “df -h

Figure 3. SD Card mounted on /dev/sdc

  • This command displays all mounted hard drives. In this particular case (Figure 3) I had my primary hard drive “/dev/sda” and the SD card “/dev/sdc” (It may be different on your machine).
  • Now that we know that  our SD card is mounted as device /dev/sdc, we can  copy the Raspbian image to the SD card using the following command: “sudo dd bs=1M if=20xx-xx-xx-wheezy-raspbian.img of=/dev/sdc“. Its imperative that this command is typed exactly as shown and that it would be executed in the same directory that contains the Raspbian “.img” file..which is our case was the “Documents” directory under “/home/halherta”. This command will take a few minutes to complete.
  • Once it completes you can remove your SD card from the card reader and plug it into your Raspberry Pi. Make sure that your Raspberry Pi  (RPi) is connected to your local area network  via a wired connection to your router/ switch.

Starting up Your Raspberry Pi and logging into it remotely via SSH

  • Now power your Raspberry Pi. You should see the LEDs start to come up implying that the Raspbian image has been successfully started. Once the green “LNK” LED and the “10M” orange LED light up on the RPi board, we can assume that the Raspbian image booted and an IP address has been assigned to the Raspberry Pi. At this point we would like to figure out the IP address assigned to the Raspberry PI by the DHCP server running on our router. To do this we will use an IP Scanner tool. I highly recommend using Advanced IP Scanner v2. This is a windows program and should run on the host (Windows) OS. The program is freeware. Download it and install it. Once installed start it up and hit the large “Scan” button.  This will provide you with the IP addresses of all the machines connected on your local area network. One of them should be labelled “Raspberry Pi Foundation” under manufacturer. This is the IP address on your RPi. Based on Figure 4, the IP address of my RPi is 192.168.0.110

Figure 4. Identifying the IP address of the RPi board using an IP Scanner

  • Now that we know the IP address of the RPi board, we will log in to it remotely via SSH. SSH is an encrypted version of telnet (with a few additional goodies) that can give us complete control over  the raspberry Pi from the command line over our network. To login into the Raspberry Pi over SSH we need to type in our Kubuntu terminal: “ssh 192.168.0.110 -l pi“. Basically we’re typing the name of the command “ssh” followed by the IP address of the RPi, followed by the username by which we wish to log on…remember the default username for the Raspbian Distribution is “pi”. Once we do this we may be asked if this is a safe connection (if this is our first time to ssh into the RPi). We can choose yes and then enter the password when prompted. again the default password is “raspberry”. Once we do this, our Kubuntu terminal window becomes logged into the Raspberry Pi. Any commands that we type into that window from now on will affect the Raspberry Pi and the not our Kubuntu installation.

Figure 5. Logging into the RPi via SSH and typing “sudo raspi-config”

 

Configuring your Raspberry Pi over SSH

  • The next step is to type “sudo raspi-config” (figure 5) Once you do this the raspi-config tool will run (figure 6)

Figure 6. ncurses based raspi-config tool

  • From the raspi-config menu, first select update. This will update the raspi-config tool.
  • The Raspbian image is designed to expand into 2GB space on your SD card. This means that if you are using a larger SD Card say 4GB or 8GB the additional space is not part of the root file system partition. In order to be able to use all the space on your SD card  select the “expand_rootfs” and hit enter. This will enable the root file system partition to be expanded to file the entire SD card. The actual partition expansion will happen on reboot.
  • The other major option is “memory split”. Hit “Enter” and then choose an appropriate memory split ratio. I recommend the 224MB for the ARM Core and 32MB for the GPU. This way you should have plenty of RAM for running many apps on your OS. 32MB of RAM for the GPU is plenty…unless you plan on doing a lot of gaming or image and video processing.
  • Select the “224MiB for ARM, 32MB for VideoCore” setting using up/down arrow keys then hit the right arrow key once to highlight “OK” and hit enter again.
  • For the other options, I highly recommend that you explore them…..I don’t recommend overclocking the RPi (overclock option) and I keep the defaults for the “ssh” (run SSH server on start up) and “boot_behavior” (boot into the command line).
  • When your done use the right/left arrow keys to select finish. This will cause the RPi to reboot with all the requested changes. This reboot might take a few minutes if you selected to expand the root file system partition. Note that when you reboot you lose your SSH connection and your console window will now be associated with your Kubuntu machine again.
  • When the RPi reboots, SSH into it again via “ssh 192.168.0.110 -l pi” as before.
  • So now we do what we ought to do whenever we have a fresh debian-based Linux distribution install complete…..type “sudo apt-get update” followed by “sudo apt-get upgrade” or alternatively we can do both at the same time “ sudo apt-get update && sudo apt-get upgrade“. The first command consults the /etc/apt/sources.list and updates the database of available packages. The second command checks updates for all installed packages and then prompts to download and install them. When it does this accept the updates and hit enter. When the second command completes its task you will have the most up-to-date Linux OS available for the RPi.

Remote login into the PI Using VNC from Kubuntu (Guest OS)

SSH is great if you want to remotely access the RPi from the command line. The Raspbian OS does come with a Desktop GUI environment called LXDE. If you want to access the LXDE desktop you need to type “startx” in the command line window. This will not work over SSH but will work if you have a screen connected to the Raspberry Pi board via HDMI.

  • To remotely access the LXDE Desktop from Kubuntu we will use the VNC protocol. First we need to install the VNC server software on the  the RPi. To do this, SSH into the Raspberry Pi and type “sudo apt-get install tightvncserver“. This will install the VNC server software on the RPi. Then type “tightvncserver” to configure the VNC server for the first time. You will then be asked to enter a password (8 characters only) I used “raspberr”. You will then be prompted to enter an optional “view only password”. This is not needed and you can choose to not set one by saying no. the next step is to type the following to start the VNC server: “vncserver :1 -geometry 1280×720 -depth 24“. This starts a vncserver on vnc port 1 with a resolution of 1280 by 720 and a color depth of 24. At this point the VNC server should be running on the Raspberry Pi.
  • Now open another console window on your Kubuntu Desktop and install a VNC viewer (client) on the Kubuntu OS with the command: “sudo apt-get install xtightvncviewer “. Then in the same console window (Kubuntu) type “xtightvncviewer &“. The ampersand allows us the run the application while not blocking the terminal window.

Figure 7. Start the VNC server on the RPi and the VNC viewer on the Kubuntu VM

  • This will open the VNC viewer in Kubuntu(a small messagebox…see Figure 7). Type in the VNC server address that you want to connect to i.e. “192.168.0.110:1″.  You will then be prompted to enter your VNC password. Type that in and press enter. You should see the window shown in Figure 8.

Figure 8. Accessing Raspbian’s LXDE Graphical Desktop over VNC in your Guest OS.

If you want to VNC into your raspberry Pi from your Windows Host OS, be sure to download the RealVNCviewer for Windows. The software is free though you may be asked to provide some information before you can download it. Once you download it, run the program and enter 192.168.0.110:1 as the address of your vnc server and then type in your password when prompted. There may be a “are you sure you want to connect” warning. Just confirm. Obviously in order for this to work, the VNC server, must still be running on the RPi .

 

 

 

This entry was posted in Raspberry Pi. Bookmark the permalink.

7 Responses to Installing Raspbian on the Raspberry Pi & using SSH and VNC to remotely connect to the Raspberry Pi

  1. Leopoldo says:

    Thank you so much

  2. PCees4u says:

    It works fantastic! Excellent blog!

  3. Perfect! Seems like such a simple thing but having never set this stuff up via SSH this blog helped me out immensely. The whole process was so clear, concise, and easy to follow, that for once I was not the bottleneck in the equation.

    Thank you for your work!

  4. Cedric Quentin says:

    Thanks so much mate !! It worked straight away !!

  5. Pingback: Basic setup RaspberryPi | RSBox

  6. Peter says:

    Thank you very much! So well explained! :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>