Setup Raspberry Pi via SSH and Remote Desktop Connection with VNC Server

In this tutorial I will setup a Raspberry Pi 3 Model B via SSH and I will setup remote desktop connection for my Raspberry Pi with VNC Server. You can use all the configurations in this tutorial on the other Raspberry Pi boards.

Parts Required

  • Raspberry Pi
  • 8 GB SD Card or Micro SD Card if you’re using a Raspberry Pi 2, 3 or B+
  • Ethernet Cable

Installing Raspbian Operating System

Raspbian is a free operating system based on Debian optimized for the Raspberry Pi hardware. An operating system is the set of basic programs and utilities that make your Raspberry Pi run.

Step 1 – Download  the Image in the following link: 
https://www.raspberrypi.org/downloads/raspbian/

After downloading the .zip file, unzip it to get the image file (.img) for writing to your SD card.

Step 2 – Writing an Image to the SD Card.
        
Download the software Win32 Disk Imager, a tool for writing images to USB sticks or SD Cards.

https://sourceforge.net/projects/win32diskimager/

After install, open the software, select the image file you extracted earlier and select the drive letter of the SD card in the device box. Click write and wait for the write to complete.

Close the software and eject the SD card.

Setup the Raspberry Pi via SSH

The easiest way to setup the Raspberry Pi would be directly to my laptop screen without using an external monitor, to do that I will connect the Raspberry Pi to my computer via SSH with a program called PuTTY. PuTTY is an SSH client, for the Windows platform. PuTTY is an open source software that is available with source code and is developed and supported by a group of volunteers.

You can download PuTTY in the following link:
http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

Step 1 – Connect the Raspberry Pi to your router, check and take not of its IP, or in my case I use Raspberry Pi 3 wireless connection.

Step 2 – Open PuTTY, insert the Raspberry Pi IP and click open (In my case 192.168.2.54).

Step 3 – Put the Raspbian default id and password.
                ID: pi                 Pass: raspberry

Now you can do everything you want in the Raspberry Pi command line.
Make sure your Raspberry Pi is up to date by running the following commands:

             sudo apt-get update
             sudo apt-get upgrade

If you dont know how to access your router to discover Raspberry Pi IP, you can access the Raspberry Pi with a keyboard and an external monitor. Open the command line, write the command “ifconfig” and check the Ethernet or Wireless IP.

But if you want to configure your Raspberry Pi with a keyboard and an HDMI monitor you need to open the config.txt file in the SD Card, and uncomment the line hdmi_safe1, or you will not get the HDMI signal in your monitor.

Installing the Raspberry Pi VNC Server

Step 1 – Install the tightvncserver with the following command:
             sudo apt-get install tightvncserver

Step 2 – Setup and run the VNC server with the following command:
vncserver :1

Step 3 – Now you will need to setup a password for connecting to the Raspberry Pi remotely via the VNC client. The password can’t exced 8 characters.

Step 4 – Next it will ask if you want a separate view only password, simply enter “n” for this.

Step 5 – Once the previous steps are all done the server will be up and running. The following command will need to be run every time the Raspberry Pi reboots or for some reason the process is stopped.
            
vncserver :1 The Raspberry Pi VNC server should now be up and running correctly. If you want to have the VNC server to start up automatically at boot, then follow the next steps.

VNC Server Start Automatically

Step 1 – First open the rc.local file by entering the following command:

              sudo nano /etc/rc.local

Step 2 – Now enter the following instruction before the exit 0 line.     

               su – pi -c ‘/usr/bin/tightvncserver :1’

Step 3 – Save and exit pressing Crtl + X then y. Reset the Raspberry Pi.

Step 4 – You can confirm that the server is running by use the following command.

              vncserver :1

              It should say “A VNC server is already running at :1”

Step 5 – If you need to shutdown the server, enter the following command:

             vncserver -kill :1

Setting up the VNC Client on your PC

I’m going to use realvnc to install and set up a VNC client on my computer, but you can use others.

Step 1 –  Download the VNC viewer client in the following link:
https://www.realvnc.com/download/viewer/

Step 2 – Install and open the VNC Viewer, enter your Raspberry Pi IP address with the port 1, in the field that says VNC Server. Mine is 192.168.2.54:1.

Enter the password that you set earlier and the VNC window should load and you will now have remotely access to your Raspberry Pi.

Video

Bruno Silva

Author: Bruno Silva

Portuguese Electrical Engineer with special interest in Data Science, Robotics, Automation and Embedded Systems. With a degree in Electrical and Computer Engineering in the field of Energy and Automation and currently studying Master's Degree in Electrical Engineering.

2 thoughts on “Setup Raspberry Pi via SSH and Remote Desktop Connection with VNC Server

Leave a Reply

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