In this post, we are going to look at 3 different methods by which you can remotely access the Raspberry Pi to make it a bit easier to work with it. The first one is SSH, which will allow you to remotely access the terminal. The second one is a remote desktop connection, which will allow you to access the Raspberry Pi desktop for times when you need to interact with the UI. The 3rd one will allow you to directly access the files and folders so that you can easily obtain or transfer files between the Raspberry Pi and your computer.
The video above goes into further detail for each one of them and I recommend watching it first to get an understanding of the different methods.Step 1: Connect to Your Local Network
For all three methods to work, the Raspberry Pi has to be connected to the same network as the computer from which you want to remote access into it. There are several ways in which you can do this.
If you plan on using a wired connection then simply plug in the ethernet cable in the board and plug in the other end of the cable into your home router. The board should automatically connect to the network.
Wireless (with display/keyboard/mouse):
If you plan on using a wireless connection then you simply need to connect to the network by clicking the wireless network icon in the taskbar, entering the password and clicking OK. The board should automatically connect to the network. Please watch the video for an example of this.
Wireless (No display, headless mode):
You can also connect the board to the network by creating a wpa_supplicant.conf file in the boot directory of the microSD card. The Raspberry Pi operating system checks this file when it first boots up and if it is present, then it will use the network details contained within it to connect to the network. You can download the template file from the link below and update it with your country code, network name and password. It is recommended to use a text editor like Notepad++ or Sublime Text 3 to create the file. Once done, simply copy it over to the boot drive as soon as you finish flashing the image, but before you boot the board for the first time.
WPA template file: https://www.bitsnblobs.com/wp-content/uploads/2020/05/wpa_supplicant.txt
Use the following link for a list of country codes: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
Once connected to the network, we need to obtain the board's IP address. You can do this in many ways, but one convenient method is using software like Angry IP Scanner. Please watch the video if you need to see it in action. The software simply scans your local network and lists all the active devices along with their IP addresses. The IP address for my board is 192.168.1.37 and if your board shows up then you can be sure that it has successfully connected to your network.Step 2: SSH Into Your Board
If you've used the Raspberry Pi before then you will have used the terminal window at some point. Using the terminal allows you to easily create scripts, update software and so on. By default, you can access and use the terminal by connecting a display and keyboard to the board, but this is not always convenient, particularly if you are using the Pi Zero - which does not have a full-sized USB port nor a full-sized HDMI port. SSH allows you to access the terminal without the need for a display or keyboard, which makes it very convenient. More importantly, you can also copy/paste commands and scripts from your main computer instead of typing everything. SSH stands for Secure SHell and it allows you to securely communicate to a device over an unsecured connection. There are two main ways by which you can enable SSH.
If you have a display, keyboard and mouse connected then you can simply open up the "Raspberry Pi Configuration" window from the "Preferences" menu and then switch to the "Interfaces" tab. You can then simply click the radio button next to SSH which says "Enabled" and then hit OK. You can watch the video to see this being done.
No Display, Headless Mode:
If you don't have access to a display then you can simply create an empty file with the name "ssh" and copy this to the boot drive. Do not add an extension to the file. It is recommended to use a text editor like Notepad++ or Sublime Text 3 to create the file. Copy this file soon after you flash the image but before you boot it for the first time. This will enable SSH for you.
Once done, you simply need to open up a terminal window on your computer (Command Prompt for Windows and Terminal for Mac). Once done, simply type in "ssh firstname.lastname@example.org" and hit enter. Please be sure to update your IP address in that command. It will then ask you if you want to remember the host and you can type in yes, followed by pressing the enter key. It will then ask you for a password and by default, this is "raspberry" without the quotation marks. ONce you enter the password, you will log into the board and you can then access the terminal and run commands as if you were directly connected to the board using a keyboard.Step 3: Remote Desktop Connection
SSH is useful when you want to execute text-based commands and scripts. However, sometimes you will need to access and interact with the graphical user interface or GUI and in times like these, a remote desktop connection is useful. Gaining remote access is not at all difficult. You simply need to run two commands which will install the remote connection server on the Pi.
These commands can be run directly on the Pi terminal or it can be run by first logging into the board using SSH. Once at the terminal, simply type in "sudo apt-get install tightvncserver" and enter y to confirm the install. This will install tightvncserver for us. The next command we need to run is "sudo apt-get install xrdp" and enter y to confirm the install. This will install xrdp which will enable remote access.
All that's needed to be done now is access the desktop. To do this, open up the "Remote Desktop Connection" application on Windows and enter the board's IP address. It will take you to a login screen where you will have to enter the default username which is "pi' and the default password, which is "raspberry". Once done, you will be taken to the Raspberry Pi Desktop where you can interact with the board remotely and do everything as if you are physically connected to the board using a display, keyboard and mouse.
If you are using a Mac, then you will need to first install the "Microsoft Remote Connection" app from the app store. You can then create a new connection by typing in the IP address, username, password and connection name. Finally, double click the connection name to start the connection and you will be taken to the Raspberry Pi Desktop. Please watch the video as we demonstrate this for both a PC and a Mac.Step 4: Enabling FTP
Using a remote desktop connection is useful but you cannot directly copy files between your PC and the Pi Desktop by using it. Luckily, there is an easy way for us to do this remotely and that is by using FTP or the File Transfer Protocol.
Setting up FTP is simple as well. We simply need to first update the package information by running "sudo apt-get update". Then, we need to run the "sudo apt install proftpd" command which will install the FTP server for us. And that's all you need to do. By default, there is no restriction on the directories which can be accessed by using FTP. If you have multiple users then it would make sense to limit user access to only their directory which is /home/user. You will need to update the configuration file to do this and for that, you will need to run the "sudo nano /etc/proftpd/proftpd.conf" command which will open up the config file in a text editor. Scroll down to the "#DefaultRoot" line and uncomment the "#" which will enable this. Once done, simply save the file by pressing "CTRL+X" then "y", then "ENTER". You will then need to reload the service by running the "sudo service proftpd reload" command. This will put the new configuration into effect and we will only be able to access the /home/pi directory.
Accessing the files and folders is just as easy. You can open up a web browser and type in "ftp://192.168.1.37" and then log in with the default username which is "pi" and default password which is "raspberry". You will then be able to view the files and even download them. It will keep asking you to authenticate the session for security purposes. This is not entirely convenient and the recommended way is by using something called an FTP client like FileZilla. Simply download and install it and then enter the connection details in the top bar, as shown in the image - IP address, username, password, and port which is 21. Once done, click the "Quickconnect" button and you will be able to connect to the board. The Raspberry Pi files and folders will be shown on the right half and the file system of your computer will be on the left. You can drag files across to enable transfers. This way, you can easily retrieve the files you need and manage the file system.
That's how easy it is to remote access your Raspberry Pi using three different methods. If you like helpful posts like this, then please consider subscribing to our YouTube channel as it helps tremendously.
Thank you for reading!