# 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!

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!

# 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?

Wireless Control with Raspberry Pi. The phone acts as the router and the client, and the Pi acts as the server. A hotspot is created so they are on the same
Wireless Control with Raspberry Pi. The phone acts as the router and the client, and the Pi acts as the server. A hotspot is created so they are on the same

# 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!

Command Line Interface
Command Line Interface

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.

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:

  1. The router (always connected!)
  2. My phone
  3. My computer
  4. My printer

If I check the addresses for my devices, it would look like this:

Order Device IP Address
1 The Router 192.168.1.1
2 My phone 192.168.1.2
3 My computer 192.168.1.3
4 My printer 192.168.1.4

Notice any patterns? There's a common prefix - 192.168.1, then a dot ., then a number in the order of joining!

# Requirements

  1. A phone (iOS or Android)
  2. A Raspberry Pi
  3. Some brain cells 2
  4. A monitor, keyboard and mouse for setup.

Raspberry Pi
Raspberry Pi

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

iOS
Android

For setup, you do not need to create an account -- you'll only be using Termius on this phone.

# Raspberry Pi Setup

  1. You'll need to plug in the monitor, keyboard and mouse into the Pi.

  2. Start a personal hotspot on the phone.

  1. Head to Settings
  2. Click on Personal Hotspot
  3. Enable "Allow Others to Join"

You're done!

  1. Head to Settings
  2. Click on Network & Internet
  3. Click on Hotspot & Tethering
  1. Once the Pi is up, go to the top right of the screen, and click on the Wi-Fi icon.

  2. Select your Wi-Fi network, and key in the password.

  3. You're done!

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

# 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 pi for this module!
  • Each user has a password. For the pi user, it's set to SPS.

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

  1. Question: Did you use an Android device or an iOS device for the hotspot?

Congratulations! A tried and tested route.

  1. 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.
  1. Go to Termius.
  2. In the sidebar, go to Terminals.
  1. In the text bar up top, click it, then key in: ssh pi@172.20.10.2

  2. You should have a pop up asking for a password. Key in the default password SPS.

Congratulations, you're in! Absolute H A C K E R !

Continue on to Step 2 -- SSH Process.

Congratulations! A tried and tested route.

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

  1. Tap on SP3275. Locate its IP address. Note this down!

  2. Go to Termius.

  3. In the sidebar, go to Terminals.

  4. In the text bar up top, click it, then key in: ssh pi@IP Address where IP Address is 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.

  1. SSH process

Now that you are logged in to the pi, you should see something like this!

SSH Interface on Termius
SSH Interface on Termius

This now serves as the primary way to communicate with the Pi.

Just like any graphical interface, we are currently in the home folder.

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

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.

# Gracefully Shutting Down

To shut down your Pi and save all the data inside, run:

./shutdown.sh

# 📋 Quick Reference Guide!

  1. Create your personal hotspot.
  2. Open Termius and navigate to Terminal.
  3. SSH into the Pi. ssh pi@(ip address) Password is SPS.
  4. Run the data copying script. ./live_copy.sh

  1. Internet Protocol Address

  2. Likely will be required.