Login

Set up Remote access on Raspberry Pi 3


Objectives

  • Enabling the server configuration of Raspberry Pi
  • Connect to Raspberry Pi via Secure Shell (SSH)
  • Connect to Raspberry Pi via PuTTy
  • Access Raspberry Pi from a remote computer and run a python code

Things

For this project, you will need

  1. Raspberry Pi 3 [RPi 3] board (quantity: 1 no.)
  2. VNC Viewer software
  3. Micro SD card (quantity: 1 no.)
  4. 5V power adapter (quantity: 1 no.)
  5. Micro USB cable A to B (quantity: 1 no.)
  6. WiFi router / mobile hotspot (quantity: 1 no.)

Let’s begin!

Many a time, you may not have an HDMI/ VGA monitor. For this reason, remote access of Raspberry pi becomes necessary in order to cast its screen on your computer or mobile phone. You can access the command line of Raspberry pi by enabling SSH (Secure Shell). The GUI (Graphical User Interface) of Raspberry pi can be accessed using VNC (Virtual Network Computing) or RDP (Remote Desktop Protocol).

 

Step 1: Enabling SSH to access the command line remotely

There are many ways to do this,

  1. Launch Raspberry Pi Configuration from the Preferences menu
  2. Navigate to the Interfaces tab
  3. Select Enabled next to SSH
  4. Click OK

Alternatively, raspi-config can be used in the terminal: (Hint: Type Ctrl+Alt+T to launch terminal)

  1. Enter in a terminal window
    sudo raspi-config
  2. Select Interfacing Options
  3. Navigate to and select SSH
  4. Choose Yes
  5. Select Ok
  6. Choose Finish

Alternatively, use systemctl to start the service

sudo systemctl enable ssh
sudo systemctl start ssh

After enabling SSH you need to install a software called putty.exe for Windows OS. For Mac and Linux SSH is builtin. Putty will ask you to put the IP address. This can be obtained by typing in the command line of pi

ifconfig

This will show the IP address of Raspberry Pi . This is possible only if you have an HDMI screen connected to it. If you have not connected a screen to it you can connect your raspberry pi to your router using an ethernet cable and you can check the IP address in router’s client page. Note down the IP address as we need to enter this in putty software. Make sure that you are connected to the same network.

Putty will ask the IP address of the remote device. You need to enter the IP address of Raspberry Pi and hit open.

It will open a command line interface to the pi which will be shown something like this pi@raspberry

Now you can create a new file or program in this folder and run it using commands only.

for Example:

In the command line, in order to create a python program, you can type

sudo nano ledblink.py

This will open a text editor which will be blank, now you can write a program here.

After writing the program you can exit by saving the program.

Now you need to type the following command to run it.

python ledblink.py

Step 2: Accessing the GUI of Raspberry Pi remotely

The GUI of the pi can be obtained by using RDP or VNC in raspberry pi. Since you have access to the command line interface of pi using putty you can install VNC on it by typing following command.

sudo apt-get update
sudo apt-get install realvnc-vnc-server realvnc-vnc-viewer

Now enable VNC Server. You can do this graphically or at the command line.

ENABLING VNC SERVER GRAPHICALLY

  • On your Raspberry Pi, boot into the graphical desktop.
  • Select Menu > Preferences > Raspberry Pi Configuration > Interfaces.
  • Ensure VNC is Enabled.

ENABLING VNC SERVER AT THE COMMAND LINE

You can enable VNC Server at the command line using rasp-config

sudo raspi-config

Now, enable VNC Server by doing the following:

  • Navigate to Interfacing Options.
  • Scroll down and select VNC > Yes.

Now by installing VNC viewer software on your PC or mobile, you can connect to the pi by entering the valid IP address. A login screen will appear which will ask username and password and then a GUI will appear.

The same can be done with the help of RDP instead of VNC. Since RDP is builtin in Windows. First, you need to install xrdp in raspberry pi by typing following command in raspberry pi terminal

 sudo apt-get install xrdp

This will take some time to install XRDP. The login is same as VNC. Enter the username and password in Microsoft Remote Desktop application or any RDP application. First, you may need to type the IP address of remotely connected Raspberry Pi. Then you will be requested to enter username and password.

We would love to see what you build out of these learnings!

Click here to submit your projects, share it with the world and stand a chance to be rewarded.

top

Knowledge and Content by Li2 Technologies | © 2021 NASSCOM Foundation | All rights reserved

X