It’s easy to create raspberry pi projects like the time lapse camera, but accessing
the files is not exactly straight forward. In this video 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 methods we will be covering here do not allow you to access the board from outside
your home network. You can theoretically use all three methods from anywhere in the world
by changing your network settings. But if not done correctly, then you will create a
security risk by which anyone can remotely access your network.That is the reason why
I will not be talking about port forwarding in this video.
Let’s first take a look at SSH. By default, if you want to work with the raspberry
pi, you have to connect a keyboard and mouse. You can use a touch screen like this one but
you would still need a keyboard to type commands. Using this setup is OK, but you will soon
end up with a mess of cables particularly when using the PI zero which needs additional
adaptors as it does not have a full-sized USB port nor a full-sized HDMI port.
If you’ve worked with the raspberry pi, then you will have used something called a
terminal to create scripts, install software and so on. If you have a keyboard, mouse and
display connected, then you can simply open up with terminal like so and use it. This
will work just fine. But many a times, it’s easier to use a computer to control the pi
as you already have a keyboard, and mouse connected to it and most importantly you can
easily copy scripts and commands instead of typing it all. This makes things efficient
and that is why SSH is very useful. It stands for secure shell, which is nothing but a protocol
that allows you to securely access a remote device over an unsecured network.
To use SSH, there are a few things that need to be done.
Firstly, the raspberry pi has to be on the same network as your computer. If you are
using a wired connection then you need to plug in the ethernet cable to the board. If
you plan on using a wireless connection, then you simply have to click this icon, select
your network and enter the password. If you want to use a wireless connection, but do
not want to connect a display or keyboard then you need to create a WPA config file.
This needs to be copied to the boot drive before you power on the board for the first
time. There will be a link in the description to a template file that you can use. You simply
have to update your country code, network name and password. You then simply copy this
to the boot drive on the microSD card and power on the raspberry pi.
By default, SSH is disabled, so this will need to be enabled as well. You can do this
by opening up the preferences window, switching to the interfaces tab and then enabling SSH.
Simply click OK and that’s all you need to do.
If you cannot access the desktop like this, then you can also enable SSH by creating an
empty file in the boot drive with the name SSH. You do not need to add any extension
to the file. You will want to do this soon after you flash an image to the microSD card
and this will enable SSH for you.
We then need to obtain the IP address of the board and this can be done by using software
called angryIPscanner. The software will scan your network and report any active clients.
This way, you will be obtain the IP address of the board, and mine is shown here which
is 192.168.1.37.
In order to SSH into the board from a computer, we would need to open a terminal window. If
you are using a mac, then you can simply use the built-in terminal. If you are using a
PC then you can use the built-in command prompt. You simply need to type in ssh space pi @ the
IP address of your board. It will then ask you if you want to save the host, simply type
in yes and then enter the default password which is raspberry. Once done, you will successfully
log in to the raspberry pi terminal and you can then access all the commands as if you
were executing them on the board itself.
SSH is useful when you are mainly interested in creating scripts or installing software
and you don’t need to access the desktop or user interface. Remotely accessing the
desktop is also possible and that is what we will look at next.
In order to access the desktop remotely, we would need to run two commands which will
install tightvncserver and xrdp. This will then allow us to connect to the board. These
commands can either be run from the raspberry pi terminal by using a keyboard or they can
be run by first using SSH to log into the board.
To install tightvncserver, simply run the command shown on screen. It will ask you to
confirm the install so simply type y and press enter. Wait for it to download and install
the required package. Installing xrdp is just as easy. You simply need to run the command
shown on screen, confirm the install and wait for it to complete. That’s all we need to
do here.
If you are using windows, you can simply open up the remote desktop connection program.
Then type in the IP address of the board and click connect. Click yes on the prompt that
appears and you will be taken to a login screen where you will have to enter the credentials.
The default username is pi and the password is raspberry. Click OK and you will be taken
to the pi desktop. And just like that, you can access the terminal, files and do pretty
much anything you can when directly connected to the pi. Here are the time lapse images
we took in the previous video.
If you are using a mac, then you will need to install the Microsoft remote desktop app
from the App store. Then open the app, click the new button and enter the IP address, username,
password and a connection name. Simply double click the connection name and you will be
able to access the raspberry pi desktop.
This type of a remote desktop connection is useful when you need to access the desktop
but you do not want to connect a separate display or do not want to connect an additional
keyboard and mouse. Although this is useful, you cannot directly copy the files to your
computer. The raspberry pi desktop is separated from your computer and you can only control
it remotely.
The easiest way by which you can transfer files back and forth is by using FTP or the
file transfer protocol. Installing this is simple as well. First, run the sudo apt-get
update command to update the package information. We then need to run the sudo apt install proftpd
command which will install everything we need to enable the FTP server. Once done, we can
update the config file which is optional. We can open the config file in a text editor
by running the command shown on screen. The only thing we will be doing here is uncommenting
the defaultroot statement. Doing this limits user access to their own files that is the
home/user directory and prevents users from accessing files belonging to other users.
The default username is pi, which means we will only have access to the home/pi directory.
If only you will be accessing the raspberry pi, then you do not really need to make this
change, but at least you know how to do it in case you need to. Once this is done, we
simply reload the service and that’s all we have to do here.
You can then open up a web browser and type in ftp followed by the IP address of your
board as shown here. You will be asked to login so enter pi as the username and raspberry
as the password. This will then list out the home directory and you can navigate the folders
and even download files. It will keep asking you to authenticate the session as a security
measure. This is not the recommended way by which you
can work with the files, and it is strongly recommended that you download an FTP client
like filezilla, which is free to use.
Once installed, simply open it up and enter the details in this top bar - the IP address
of your board, username which is pi, password which is raspberry and port which is 21. Once
done, click quickconnect, confirm the connection and you will then be able to browse the files
and folders. You can simply drag across the files you are interested in and this will
initiate the transfer. You can even upload files by dragging them from left to right.
Another thing that you can do is save the connection details as a new site. The next
time you want to connect to it, you will simply have to click connect instead of typing all
the details.
You can then navigate to the location where you copied the files to view them. And that’s
how easy it is to work with the raspberry pi by remotely accessing the terminal, desktop
and even the file system.
I hope you liked this video, and I do hope you consider subscribing too. Thank you for
watching and I will see you in the next one.!