When you use a pi in a project you might not have a screen attached to it, or when you have a screen attached tot he pi you don’t have physical access to it all the time.
So how you do control the pi then? There are multiple options for remote access to the pi.
Here are some of the options:
Lets start at the top.
SSH, or Secure Shell, is an encrypted networking technology that enables you to manage computers and servers from the command line over a network.
This makes SSH handy of you want to quickly connect to a raspberry pi from a terminal window on any other computer. On the raspberry pi it is possible to install an OS without a graphical user interface, or you don’t install a screen. In these conditions the only easy way to connect to the pi for quick access is using SSH. It’s especially useful when creating Internet of Things (IoT) projects, as these may be embedded inside other hardware.
SSH also enables you to share files to, and from, a Raspberry Pi using SCP (secure copy) on the command line, or SFTP (SSH File Transfer Protocol).
Use SSH on a Raspberry Pi with PC
You don’t need to install any software to start using SSH. Linux, mac OS and Windows (Windows 10) have a SSH command-line application installed by default.
Note: On older Windows you will need to download an SSH client, the most commonly used one is called Putty but in this tutorial we are going to install MobaXterm on our windows machine.
To use SSH you will need an user name and password. The standard password on the Raspberry pi OS is raspberry. For security reasons we strongly recommend you to change the default password when installing any new OS on the PI.
SSH uses an encrypted network, so it doesn’t send your password as plain text. More advanced users can control the encryption keys, using ssh-keygen. For now, we’ll look at setting up and using secure shell.
Activating SSH on the RPI
For security reasons the SSH acces in disabled by default in the Raspberry Pi OS. To enable SSH on your Raspberry Pi, chose Menu > Preferences > Raspberry Pi Configuration. You will start a program as in the picture below. Chose the interface tab and enable SSH.
Press OK and reboot your system
Wait a minute I use a headless Raspberry Pi what do I do now?
Well this is a little more complex. Shutdown your pi and place your SD card into a computer.
Open the boot partition (when using windows this will be the only partition visible) create a new, empty, file called ssh and eject the SD card.
Now when you start your pi up this will automatically enable the SSH.
Activate SSH client on Windows:
Linux and macOS both support SSH out-of-the-box; skip ahead if you are using one of those operating systems. Thought windows 10 supports SSH you’ll need to activate it. This is the reason why I use MobaXterm, it’s a free program that creates a local terminal like the one on Linux. You can download its here.
Windows 10 supports SSH, but you need to activate it. Click on Search and look for ‘Manage Optional Features’. Click it in Search to open the Settings window.
Click ‘Add a feature’ and wait for the list of Optional Features to load. Scroll down the list to Open SSH Client (Beta). Click Install.
Get Your IP address
Note: if you use a headless version (a setup without a screen) see at the end of this section on how to get you’r pi’s ip.
Connect your Raspberry Pi to a local network. Use wireless LAN, or connect the Raspberry Pi directly to a router/switch using an Ethernet cable. Open a Terminal window and enter the following command (one needs a keyboard and mouse connected to the pi to make this work, see below on how to do its without).
You should see:
In my case the hostname is PITop but when you have a fresh install the hostname will be raspberry pi. Notice that the hostname is also mentioned in the terminal window itself behind the user name.
In some circumstances you can use this hostname to connect to your pi. Although this is not a reliable way to connect to your pi, it works in some cases. In my case this doesn’t work and I have to use a IP (Internet Protocol) address of my pi. Enter following command to get your IP:
This will return four numbers separated by dots. For instance, ours is:
Write this number down. You’ll need it shortly.
Connect via SSH
On a windows PC open command prompt or MobaXterm.
On a Linux or MacOS machine open a Terminal windows.
To connect over ssh enter following command:
Replace [IP] with the IP address of the Raspberry Pi. In our case, we enter
The first time you do this, you’ll get a message saying that the authenticity can’t be established, followed by a long cryptographic hash of letters and numbers. It will say, ‘Are you sure you want to continue connecting?’
Enter yes and press RETURN. You’ll be asked to enter the password for your Raspberry Pi.
Note: on a fresh install the password is ‘raspberry’
Use MobaXterm on a Windows PC
Why MobaXterm and not Putty? MobaXterm is more graphical and when you lose connection it’s easier to reconnect then when using putty.
In MobaXterm press the start local terminal before you can connect the the pi.
in this terminal enter ‘ssh yourusername@yourpiip’. In the example below the username is pi and the ip is 192.168.0.7.
On Raspberry Pi
You will now see your usual command line replaced with pi@raspberrypi: ~$. You are now logged in and working on the command line from your Raspberry Pi. Enter ls and you’ll see Desktop, Downloads, Documents, and the other unique Raspberry Pi folders and files. You can create, edit, move, and work with files as if you were using a terminal on your Raspberry Pi.
There are limitations to SSH. A plain SSH connection can’t open programs that use a graphical interface, so you should learn to use command-line alternatives (such as nano or vim instead of Leafpad for text editing).
On Linux computers and MobaXterm, you can forward your X session over SSH, to allow the use of graphical applications, by using the -Y flag:
ssh -Y pi@[IP]
Now you are on the command line as before, but you have the ability to open up graphical windows. For example, typing:
…will open up Scratch in a graphical window.
It’s not easy to share files using Secure Shell from the command line, but it’s possible and a handy skill to learn. If you’re still accessing Raspberry Pi, enter exit at the command line to return to your local shell:
With SSH turned on, you can copy files from your source computer to the Raspberry Pi using SCP. We’ve downloaded The MagPi issue #83 PDF file to our Downloads folder. We’re going to copy it to the MagPi directory on our Raspberry Pi.
Use the scp command followed by the path to the source file, and then the destination location. The destination is pi@[IP] followed by a colon ‘:’ and the path to the destination location.
scp [source] pi@[IP]:[destination]
Replace the [source] and [destination] parts with the paths to the file and desired destination folder, and add your Raspberry Pi’s IP address.
For instance, copying the PDF file on our machine looks like this:
scp Downloads\MagPi83.pdf [email protected]:/home/pi/MagPi
This copies The MagPi issue #83 PDF from the Downloads folder on our Windows PC to the MagPi directory on Raspberry Pi.
Notice that the directory path uses backslash (‘\’) for Windows source and slash (‘/’) for the Linux destination (if you’re using a Mac or Linux machine, it’ll be a slash in both source and destination.)
Use SFTP (Secure File Transfer Protocol) in a program such as FileZilla to transfer files to and from your Raspberry Pi via a graphical interface
If you copy a lot of files back and forth from a computer to Raspberry Pi, then it’s a good idea to set up SFTP using a dedicated FTP program, such as FileZilla. Install FileZilla on your computer (it is available for Linux, Windows, and macOS).
Open FileZilla and choose File > Site Manager. Now click New Site and you can give the site a custom name, such as ‘Raspberry Pi’. Change the Protocol to ‘SFTP – SSH File Transfer Protocol’.
Enter ‘raspberrypi’ in the Host field, ‘pi’ in the User field, and your Raspberry Pi password in the Password field.
Click Connect and you will connect remotely to the Raspberry Pi. You will see all your Raspberry Pi files in the right-hand ‘Remote’ side of the display. On the left, in the ‘Local Site’ section will be all the files on your computer. Double-click directory folders in either side to navigate into them, and use the ‘..’ folders at the top of each list to navigate back up to the parent folder.
Double-click a file in Local Site to send it to the Remote section, and vice versa. Follow the FileZilla tutorial if you need more guidance.
Thougth SSH is quite powerfull, and as seen you can launch graphical programs, it’s handy to actualy have a desktop view.
So lets see how we take control over the pi screen.
You will need to interact with your Pi in order to turn on the VNC server.
(Optional) Install RealVNC
By default, Raspbian should come with a VNC server (RealVNC) installed. If you are using another operating system, you might need to install RealVNC. With most flavors of Debian (e.g. Raspbian is built on top of Debian), you should be able to use apt-get to install RealVNC. In a terminal, enter the following:
sudo apt update sudo apt install real-vnc-server real-vnc-client
Enable the VNC Server
You will need to go into the Raspberry Pi configuration tool to turn on the VNC server:
Select Interfacing Option, and then select VNC. On the next screen, select Yes, and press enter to save the changes.
Feel free to make any other changes you might like, including setting a new password and changing the keyboard layout.
Back in the raspi-config homescreen, press right arrow twice to select Finish and press enter.
We will only look at a setup where you host computer is on the same local network. This way you can make a direct VNC connection to your Raspberry Pi. This method has several up sides: it’s the easier option, does not require signing up for a RealVNC account, and can be done on a closed network (i.e. one not connected to the Internet). The down side is that you must be on the same network to access your Pi (i.e. physically connected or through a VPN). This is a known as a direct connection.
If you want to to access your Raspberry Pi over the Internet,You’ll have to register for a realVNC account
Still in your Raspberry Pi’s terminal, enter the following command:
Copy down the Raspberry Pi’s IP address, which is given as a series of 4 numbers next to inet. If you are connected over WiFi, this will appear under the wlan0 settings. If you are connected over Ethernet, this will appear under the eth0 settings.
On your host computer, head to the RealVNC Viewer downloads page to download the VNC client (known as VNC Viewer) for your operating system. Install it, accepting all the defaults.
Open VNC Viewer. At the top address bar, enter the IP address of the Raspberry Pi (once again, make sure your host computer and Pi are on the same network!).
Press enter, and click Continue when warned that “VNC Server not recognized.” You should be prompted with an Authentication window. If you did not change the login username and password for your Pi, your default login credentials are:
- Username: pi
- Password: raspberry (default password, other when you changed it!)
Heads up: it’s highly recommended that you change your password! Anyone with access to your network could easily gain access to your Pi by trying the default username and password.
Once you successfully authenticate, you should be presented with your Raspberry Pi’s graphical desktop. Now, you can do everything remotely as if you were sitting in front of your Pi with a keyboard, mouse, and monitor! If you hover your mouse over the top part of the window, you should see a drop-down box appear, giving you access to the various RealVNC settings, including closing the session.
VNC Screen Size
Now hold on, my screen is al blurry. Well this can happen when you have no HDMI connected to the pi on boot. This way it’ll default to composite output.
Here is how to force HDMI output and set the resolution.
First nano into /boot/config.txt
sudo nano /boot/config.txt
In this file delete the ‘#’ in front of ‘hdmi_force_hotplug = 1, hdmi_group=2 and hdmi_mode=1
The first command tells the pi to force its output on the HDMI port.
the 2nd and 3th will set the display to the wanted screensize. Note that in my case I opted for mode 82, your’s might differ:
|0||Auto-detect from EDID|
|15||1024×768||43Hz||4:3||incompatible with the Raspberry Pi|