- 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
For this project, you will need
- Raspberry Pi 3 [RPi 3] board (quantity: 1 no.)
- VNC Viewer software
- Micro SD card (quantity: 1 no.)
- 5V power adapter (quantity: 1 no.)
- Micro USB cable A to B (quantity: 1 no.)
- WiFi router / mobile hotspot (quantity: 1 no.)
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,
- Launch Raspberry Pi Configuration from the Preferences menu
- Navigate to the Interfaces tab
- Select Enabled next to SSH
- Click OK
Alternatively, raspi-config can be used in the terminal: (Hint: Type Ctrl+Alt+T to launch terminal)
- Enter in a terminal window
- Select Interfacing Options
- Navigate to and select SSH
- Choose Yes
- Select Ok
- 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
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.
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.
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
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.