Hacking SSH

To do anything serious with tech, Gou was going to need to learn how to make his machines talk to each other like nodes.

If he could just figure out how to make his laptop talk to his Pi, he could then do lots of other really cool things later on.

After getting his Raspberry Pi setup and configured, this is what he needed to do:

Making Linux on his Raspberry Pi talk to Unix on his Macbook was the goal. After getting his Pi setup and ready for SSH, the whole task only took him about 10 minutes.

Step One

We're going to configure SSH on your Raspberry Pi so you can connect from your computer. Let's go!

On your Raspberry Pi screen, click the RPI logo on the top-left corner, click Preferences, and then click Raspberry Pi Configuration.

Click Interfaces and make sure SSH is set to Enabled.

Did you enable SSH? Good job!

Step Two

Now, we're going to find you Raspberry Pi's IP Address. Remember to jot it down on paper. Your IP Address is like your computer's phone number (path).

On your Pi, open up the terminal. Make sure it is connected to the a network via wifi or ethernet!

Search for the app on your Pi that looks like this and fire up a terminal!

TYPE THE FOLLOWING COMMAND:

> ifconfig eth0
Use this command if your Pi is connected to a network via an ethernet cable.
> ifconfig wlan0
Use this command if your Pi is connected to a network via wifi. The IP Address is the number inside the red box after "inet addr:". Mark that down! You can also find it by typing "hostname -I".

Step Three

We're now going to connect directly to your Pi from your computer with either a terminal on Mac or the OpenSSH Client on Windows. Connect to your Raspberry Pi and let the games begin!

FOR MAC

On your Mac, open up the terminal.

Search for the app on your Mac that looks like this:

OPEN IT AND TYPE THE COMMAND:

> ssh pi@YOUR_IP_ADDRESS
Replace "YOUR_IP_ADDRESS" with the one you jotted down earlier. Your Pi's default user is "pi". If you changed it replace the "pi" before the @ with your new profile name.

ENTER YOUR PASSWORD:

> raspberry
By default, your Pi's password is "raspberry" unless your changed it (which you should do if you haven't).

Woot! You should be in.

TO VERIFY YOU ARE IN, TYPE:

> ls

You should see the files on your Raspberry Pi. If so, your Mac is officially talking to your Raspberry Pi.

FOR WINDOWS

Open settings and click on Apps

Go to the Apps & Features tab and click on Optional Features

Search OpenSSH Client to see if it shows up and is already installed

If it isn't, then click on Add Feature, search OpenSSH Client, and click install. Make sure to install the client not the server!

After you installed the client, type Command Prompt on the Windows search bar and click on the Command Prompt app to open a terminal.

TYPE THE COMMAND:

> ssh pi@YOUR_IP_ADDRESS
Replace "YOUR_IP_ADDRESS" with the one you jotted down earlier. Your Pi's default user is "pi". If you changed it replace the "pi" before the @ with your new profile name.

ENTER YOUR PASSWORD:

> raspberry
By default, your Pi's password is "raspberry" unless your changed it (which you should do if you haven't).

Woot! You should be in.

Step Four

Finally, we're going to add your computer's public key as a known host to your Pi's SSH server. This allows you to access your Pi from your computer without even needing to use a password like you did before, making the whole process a lot faster and easier! Let's see how to do it!

First, let's end the SSH session by typing and entering "exit", hitting Ctrl+D, or simply closing the terminal window (but you'll need to open it again if you did this).

NOW TYPE THE COMMAND:

> ssh-keygen

This creates two really long strings of random characters. One is a public key and the other is a private key.

Hit enter. This saves the keys to a default file location.

If it says a file already exists, it means a key pair was already generated on your computer before. You can enter y to overwrite the existing keys with new ones or enter n to keep the old ones, for what we're doing it doesn't matter what you choose.

When the "Enter passphrase" prompt appears, hit enter to have no passphrase so you do need to enter it everytime you access your pi. Hit enter again to confirm the empty passphrase.

You should now see a randomart image of your key pop up. Boom! Do not share this with anyone though, since it acts like a password.

NOW TYPE THE COMMAND:

> ssh-copy-id pi@YOUR_IP_ADDRESS
Similar to how you did before. Remember to replace YOUR_IP_ADDRESS with your Pi's IP Address and change "pi" to your profile name if you changed it.

This copies your computer's public key that you just created to the list of authorized keys in your Raspberry Pi

ENTER YOUR PASSWORD:

> raspberry
Remember that it's different if you changed it.

You should see a message saying 1 key was added if everything was entered correctly.

You can now test that this worked by typing:

> ssh pi@YOUR_IP_ADDRESS

just like you did in Step Three but now you will see that it does not ask you for a password. Since you added you computer's key to your Pi's SSH server, your Pi now "knows" your computer, and you can access it a lot faster now. Imagine all the bigger stuff you can do now! Congrats!

SSH