#
Setting up SSH
#
Legend
In this little write-up, certain steps are just for your information. They will be noted by a gray information box, like the one below!
More Information
In a box like this!
At the same time, some boxes are just a little test to see if you're still following. They have a pretty checkbox beside them and are green!
Exercise
How many Pis does SPS have?
Honestly, no idea. But great question!
#
Why?
Welcome to your very first lesson on Secure SHell (SSH) networking!
You might be wondering why you'd be learning this as part of The Earth. Well, it turns out, working with a monitor and a keyboard in the field is difficult. It'll be easier to use a keyboard and mouse that we carry around in our pockets.. hey, that's a phone, isn't it?
#
Interface
We're used to an interactive interface. In the world of programming, this is called a GUI -- or Graphical User Interface. Instead, we'll be using a text based interface, in the command line. This is Secure Shell!
In SSH, there is both a server and a client. Just imagine -- the server is the brains doing the work, the client is the one talking to you. It'll be easy to identify that the Pi is the server, and your phone is the client!
#
Basic Networking
So, your Raspberry Pi needs to talk to your phone. This means they need to be on the same network.
"Exercise"
Can you think of a way to create a network when you're outside?
The answer to the question above, which should be obvious, is to use a personal hotspot on your phone.
We will be first creating a network, getting the Pi to join it, then ssh'ing in.
Next thing: Different things on a network have different addresses. These addresses are used to find where information is to be delivered to. These are called IP Addresses1! These are usually assigned in sequence of joining, with a common starting prefix!
Let's say I've just returned home, and my phone has connected to my home network. After that, I used my computer on my home network, and finally turned on my printer to print something through Wi-Fi.
The order of stuff connected:
- The router (always connected!)
- My phone
- My computer
- My printer
If I check the addresses for my devices, it would look like this:
Notice any patterns? There's a common prefix - 192.168.1, then a dot ., then a number in the order of joining!
Why are we explaining this?
It'll come in handy later, don't worry!
#
Requirements
- A phone (iOS or Android)
- A Raspberry Pi
- Some brain cells 2
- A monitor, keyboard and mouse for setup.
#
First Time Setup
#
Installation of Termius
We'll be making your phone a SSH client. To do so, download Termius for your phone. QR codes for both platforms attached + linked.
Heads up!
Make sure you're able to bring out this exact same phone for fieldwork!
For setup, you do not need to create an account -- you'll only be using Termius on this phone.
#
Raspberry Pi Setup
You'll need to plug in the monitor, keyboard and mouse into the Pi.
Start a personal hotspot on the phone.
- Head to Settings
- Click on Personal Hotspot
- Enable "Allow Others to Join"
You're done!
- Head to Settings
- Click on Network & Internet
- Click on Hotspot & Tethering
Special Characters
You'll have to make sure the name of your hotspot has no special characters! This means renaming your phone to a friendly name. No aprostophes!
Examples:
❌ Matthew's iPhone
✅ Matthew iPhone
Once the Pi is up, go to the top right of the screen, and click on the Wi-Fi icon.
Select your Wi-Fi network, and key in the password.
You're done!
Note down the name of your Wi-Fi network, and its password. You'll need it if there's debugging to do on the field!
#
On-field SSH
⚡ Test before fieldwork!
Right, the title says on-field; but you should really try it once before heading out.
#
Explanation on SSH
Before we continue, let's explain a little more about SSH. We need to tell the client where to log in to.
Two (Three) important details!
- To login to a computer, you need to know where it is first! This is called an IP Address. 1
- Computers also have different users, each with a different username, so you'll need to know that too.
We use
pifor this module! - Each user has a password. For the
piuser, it's set toSPS.
Now, we have to specify this to our Client!
ssh pi@127.0.0.1
In this case, pi is our username, and 127.0.0.1 is the IP Address.
After telling this to a client, it will ask the server for permission to log in. Of course, the server would ask for a password, and that's the next thing you'll see. Don't worry, you won't see stars when you type in your password, but that's alright.
#
Setup
- Question: Did you use an Android device or an iOS device for the hotspot?
Congratulations! A tried and tested route.
- Check if the Raspberry Pi has successfully connected to your hotspot. Do so by checking in Control Center, and checking the number of connections. It should say 1 connection.
No connections?
Don't worry, just restart the Pi by turning it off and on again.
- Go to Termius.
- In the sidebar, go to Terminals.
Short quiz!
The starting prefix for the IP addresses generated by an iOS hotspot is 172.20.10. What would the address of the first device that gets connected (after the router) be?
172.20.10.2
In the text bar up top, click it, then key in:
ssh pi@172.20.10.2You should have a pop up asking for a password. Key in the default password
SPS.
Can't find the host?
Don't panic, the device may not be the first thing connecting to your hotspot.. Try with different IP addresses, with the same prefix!
It should look like:
ssh pi@172.20.10.n, where n is some number between 2 to 8.
Congratulations, you're in! Absolute H A C K E R !
Continue on to Step 2 -- SSH Process.
Congratulations! A tried and tested route.
- Check if the Raspberry Pi has successfully connected to your hotspot. Do so by checking in Settings > Connections > Mobile hotspot and tethering > Mobile Hotspot, and checking the connected devices at the bottom.
You should see SP3275 as a device.
Tap on SP3275. Locate its IP address. Note this down!
Go to Termius.
In the sidebar, go to Terminals.
In the text bar up top, click it, then key in:
ssh pi@IP AddresswhereIP Addressis what you found earlier.
It should look like: ssh pi@192.168.1.1.
Congratulations, you're in! Absolute H A C K E R !
Continue on to Step 2 -- SSH Process.
- SSH process
Now that you are logged in to the pi, you should see something like this!
This now serves as the primary way to communicate with the Pi.
Just like any graphical interface, we are currently in the home folder.
(Optional!) More Information
How do you check where you are in the filesystem?
pwd, or Path to Working Directory, will show you where you are currently at (Working Directory)
matthewsung
To see what's in the current directory, we want the server to list the stuff inside! Running ls (list) would show what's inside.
To move between directories, use cd (Change Directory), and specify which folder to go to.
cd Desktop moves you to the Desktop folder!
To go back to the parent folder, use cd ...
Right now, you can just run the script to log data directly. This is similar to double-clicking on the script that is in the desktop, when you were using a monitor. This is done by typing the following into the terminal, then pressing enter.
./live_copy.sh
(Optional!) More information
The little ./ before the name of the script tells us that we are trying to run the script.
Little quiz!
How do you run the live_results.sh script?
./live_results.sh
You should now see something like this, showing that the data is being logged! When the numbers flash, a new reading has been taken and it's highlighting the changes since the last readings.
What's the difference between live_copy and live_results?
live_copy copies information into the attached USB drive, while live_results just shows it.
#
Gracefully Shutting Down
Force Shutdown
Shutting your Pi down forcefully is bad (by removing the power) -- it won't know that it needs to save your data.
To shut down your Pi and save all the data inside, run:
./shutdown.sh
#
📋 Quick Reference Guide!
- Create your personal hotspot.
- Open Termius and navigate to Terminal.
- SSH into the Pi.
ssh pi@(ip address)Password isSPS. - Run the data copying script.
./live_copy.sh
