MobaXterm

Remote Acces to the Raspberry Pi

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:

  • SSH
  • VNC
  • XRDP

Lets start at the top.

SSH

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).

hostname

You should see:

hotname example

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:

hotname -I

This will return four numbers separated by dots. For instance, ours is:

Hostname's IP

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:

ssh [email protected][IP]

Replace [IP] with the IP address of the Raspberry Pi. In our case, we enter

ssh [email protected]

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 [email protected]: ~$. 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.

Visual interfaces

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 [email protected][IP]

Now you are on the command line as before, but you have the ability to open up graphical windows. For example, typing:

scratch &

…will open up Scratch in a graphical window.

Note that X11 is no longer present on Macs with macOS, so you have to download and install it separately to access graphical windows over SSH.

Copy files

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:

exit

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 [email protected][IP] followed by a colon ‘:’ and the path to the destination location.

scp [source] [email protected][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.

scp

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.)

SFTP

 Use SFTP (Secure File Transfer Protocol) in a program such as FileZilla to transfer files to and from your Raspberry Pi via a graphical interfaceUse SFTP (Secure File Transfer Protocol) in a program such as FileZilla to transfer files to and from your Raspberry Pi via a graphical interface

filezilla

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.

VNC

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:

sudo raspi-config

Select Interfacing Option, and then select VNC. On the next screen, select Yes, and press enter to save the changes.

Enable VNC on the Raspberry Pi

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.

Use VNC

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:

ifconfig

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!).

Connect to your Raspberry Pi from within the RealVNC VNC Viewer

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.

Raspberry Pi desktop in the VNC viewer

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
Change boot config

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:

hdmi_groupresult
0Auto-detect from EDID
1CEA
2DMT
hdmi_modeResolutionFrequencyScreen AspectNotes
1640×35085Hz
2640×40085Hz16:10
3720×40085Hz
4640×48060Hz4:3
5640×48072Hz4:3
6640×48075Hz4:3
7640×48085Hz4:3
8800×60056Hz4:3
9800×60060Hz4:3
10800×60072Hz4:3
11800×60075Hz4:3
12800×60085Hz4:3
13800×600120Hz4:3
14848×48060Hz16:9
151024×76843Hz4:3incompatible with the Raspberry Pi
161024×76860Hz4:3
171024×76870Hz4:3
181024×76875Hz4:3
191024×76885Hz4:3
201024×768120Hz4:3
211152×86475Hz4:3
221280×76860Hz15:9reduced blanking
231280×76860Hz15:9
241280×76875Hz15:9
251280×76885Hz15:9
261280×768120Hz15:9reduced blanking
271280×8006016:10reduced blanking
281280×80060Hz16:10
291280×80075Hz16:10
301280×80085Hz16:10
311280×800120Hz16:10reduced blanking
321280×96060Hz4:3
331280×96085Hz4:3
341280×960120Hz4:3reduced blanking
351280×102460Hz5:4
361280×102475Hz5:4
371280×102485Hz5:4
381280×1024120Hz5:4reduced blanking
391360×76860Hz16:9
401360×768120Hz16:9reduced blanking
411400×105060Hz4:3reduced blanking
421400×105060Hz4:3
431400×105075Hz4:3
441400×105085Hz4:3
451400×1050120Hz4:3reduced blanking
461440×90060Hz16:10reduced blanking
471440×90060Hz16:10
481440×90075Hz16:10
491440×90085Hz16:10
501440×900120Hz16:10reduced blanking
511600×120060Hz4:3
521600×120065Hz4:3
531600×120070Hz4:3
541600×120075Hz4:3
551600×120085Hz4:3
561600×1200120Hz4:3reduced blanking
571680×105060Hz16:10reduced blanking
581680×105060Hz16:10
591680×105075Hz16:10
601680×105085Hz16:10
611680×1050120Hz16:10reduced blanking
621792×134460Hz4:3
631792×134475Hz4:3
641792×1344120Hz4:3reduced blanking
651856×139260Hz4:3
661856×139275Hz4:3
671856×1392120Hz4:3reduced blanking
681920×120060Hz16:10reduced blanking
691920×120060Hz16:10
701920×120075Hz16:10
711920×120085Hz16:10
721920×1200120Hz16:10reduced blanking
731920×144060Hz4:3
741920×144075Hz4:3
751920×1440120Hz4:3reduced blanking
762560×160060Hz16:10reduced blanking
772560×160060Hz16:10
782560×160075Hz16:10
792560×160085Hz16:10
802560×1600120Hz16:10reduced blanking
811366×76860Hz16:9
821920×108060Hz16:91080p
831600×90060Hz16:9reduced blanking
842048×115260Hz16:9reduced blanking
851280×72060Hz16:9720p
861366×76860Hz16:9reduced blanking

2 comments On Remote Acces to the Raspberry Pi

Leave a reply:

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.