Skip to content
Jason Charney edited this page Apr 5, 2017 · 10 revisions

SSH, or Secure Shell, is a cryptographic network protocol for operating network services securely over an unsecured network. The best known example application is for remote login to computer systems by users. SSH provides a secure channel over an unsecured network in a client-server architecture, connecting an SSH client application with an SSH server. Common applications include remote command-line login and remote command execution, but any network service can be secured with SSH. The protocol specification distinguishes between two major versions, referred to as SSH-1 and SSH-2.

SSH was designed as a replacement for Telnet and for unsecured remote shell protocols such as the Berkeley rlogin, rsh, and rexec protocols. Those protocols send information, notably passwords, in plaintext, rendering them susceptible to interception and disclosure using packet analysis.

🤓 [Uncle Eddie](Edward Snowden) says: Although The encryption used by SSH is intended to provide confidentiality and integrity of data over an unsecured network, such as the Internet, the National Security Agency can sometimes decrypt SSH, allowing them to read the contents of SSH sessions.

Enable SSH on Raspberry Pi

With each new version of Raspbian, enabling SSH has become easier.

For instance, on the Pixel GUI, you can take the Raspbian Menu -> Preferences -> Raspberry Pi Configuration, click on the Interfances Tab, and click on the radio button labeled Enable in the row for SSH, then click OK. You might need to restart your device though.

Alternatively, for you command line geeks, sudo raspi-config -> 5 Interfacing Options -> P2 SSH -> Yes -> OK -> Finish

It is important to configure a hostname and a password for your Raspberry Pi.

📓 TODO: I should write how to do that later.

Connecting your Pi from another computer.

Linux users pretty much have it easy as they just need to type in ssh pi@hostname where the hostname is either the name of the device, the address of the device or server, or the IP address of the device or server.

Windows users will need to download PuTTY to install SSH. Windows used to have SSH support through aprogram called HyperTerminal, but some marketing jerks at M$ said "We don't need that, nobody will every use that." Microsoft is now looking for a way to add their own SSH program in the near future. Even if they do, PuTTY rules! You can even run it inside of Cmder as a child program.

Passwordless SSH

Let's say your Pi and your computer have a good relationship (OK, there's probably a better reason for this). So much so, your host device (the Pi) will give you permission any time you want to come over.

Linux and Mac

For Linux and Mac users, you can use OpenSSH.

⚠️ WARNING: Windows users, start here! Now would be a good time to install Chocolatey for Windows, then use choco install Cmder to install Cmder and choco install putty to install Putty

  1. You'll want to have OpenSSH installed. OpenSSH is an open source program for using the Secure Shell (SSH) protocol. If you have Linux or MacOSX, you should have this installed already. However, if you are running Windows, you'll want to get it from installing the Git Bash shell that comes with Git for Windows. I'll have instructions for doing this with PuTTY later, or you can do it now using that command I just mentioned. OpenSSH comes with Cmder which will let you run Git for Windows as well. If it were any more perfect, it would come with Atom.
  2. In Bash, run the command ssh-keygen to generate two files: id_rsa and id_rsa.pub. These files are your private key (id_rsa) and public key (id_rsa.pub) files. The will be saved in a hidden directory ~/.ssh. The directory is hidden because on UNIX systems, files and directories that start with a period (.) are hidden. To see the hidden directory, type ls -la ~. Note, that ~ is the alternate name of your home directory /home/$USERNAME where $USERNAME is your username. On your system, your username may be different from the username that is on the server. However, on a Raspberry Pi you are pi.
  3. Copy the ~/.ssh/id_rsa.pub file from your computer to a flash drive. DO NO POST THE FILE ONLINE! If you do you will breach security. Let's assume we've copied that file to a folder on the flash drive called Kevin. Yeah, pretend your name is Kevin for the moment. The id_rsa.pub file should have a continuous line of text which should start with ssh-rsa, has something like your username and computer name at the end (something like kevin@mycomputer but in the case of the raspberry pi it will likly be pi@mycomputer assuming your Pi's host name is "mycomputer"), and have a long string of characters in between which is the public security key. Give the flash drive to the Administrator to use. Oh wait, an adminstrator is you, because it is your Pi!

⚠️ WARNING! If you haven't set up your Rapsberry Pi to accept exFAT yet run this command first before plugging it in: sudo apt-get install exfat-fuse exfat-utils. The best part is you won't need to reboot the Pi.

  1. This step is for the Administrator. Copy the contents of id_rsa.pub to a file called authorized_keys which should be in the user's .ssh directory on the server, that is /home/pi/.ssh on the Raspberry Pi. In other words, copy the file contents from /media/pi/0123-4567/id_rsa.pub to /home/pi/.ssh/authorized_keys. The cool “hacker” way would have been to do this oneliner:
cat /media/pi/0123-4567/id_rsa.pub >> /home/pi/.ssh/authorized_keys

📓 NOTE: If it gives you any lip about /home/pi/.ssh/authorized_keys not exiting, just run this command mkdir /home/pi/.ssh. It wants a folder first.

Where the contents of the id_rsa.pub file are appended to the end of authorized_keys without opening a text editor like Vim.

  1. Once the administrator has copied that file to your home on the server, try accessing the shell from your computer, which is called the client. To access the server the first time, type
ssh -vvv -i ~/.ssh/id_rsa pi@mycomputer

More than likely you will need to use the IP address of your Pi rather than its hostname.

  1. Since this is your first time you may be asked a yes or no question. Type in yes. Do not type just "y" but the full word "yes".

From that point on, you can just access the server using this command:

ssh kevin@displaysthatpay.com

Windows

If you are a Windows user, you may like using PuTTY over the Git Bash program to access SSH. While there is nothing wrong with using Git Bash, one of the advantages of PuTTY is that it can remember your SSH settings and you can enable features like 256 colors. Of course, the boss will likely want you to use programs with graphical user interface (GUI) instead of a textual user interface (TUI). I know, it’s kind of a bummer, especially if you’re a fan of doing everything in Vim. But don’t let that get you down. Follow these steps to establish PuTTY.

💔 Sorry, there should be images here. I'll find some way to post images later to illustrate what is going on.

  1. Get PuTTY. They have a .msi file to install it. Use that.
  2. Once it is installed, click on the search bar (or Window Key + R) and type in PuTTYGen to open the PuTTY key generator.
  3. We need to convert id_rsa to a file called id_rsa.ppk. Click the Load button and look for the id_rsa file in the .ssh folder. This should be in C:\Users\kevin\.ssh and it should be visible. Note that in my screenshots, I’ve already done this but follow along anyway. Don’t forget to look at ALL FILES not just the .ppk files! Select it and click open.
  4. You will then get an notice. Press OK.
  5. Click on Save Private Key.
  6. You'll get a prompt asking why you didn't enter a key passphrase. Basically, it wants to know why you didn't add a password. We don't need to. Click Yes when you see the warning box.
  7. Save the file as id_rsa.ppk and click Save. You an can save it as something else somewhere else if you want, but just for the sake of clarity and organization, put it in the .ssh folder.
  8. Close PuTTYgen.
  9. Open PuTTY.
  10. In this step, you will need to do a few things: a. In the Host Name field, enter your username (pi) and the site you plan to connect to (the pi's hostname), like you would for OpenSSH. b. Let’s save these settings by typing in "RaspberryPi" into the Saved Sessions field, then click save.
  11. In the Left column, Go to Connections -> SSH -> Auth. We want to load our Private Key in the "Private key for authentication field". Click Browse.
  12. Find the id_rsa.ppk file again.
  13. (There was supposed to be an illustration here describing what happens)
  14. Just for our sake, click on Session, select the "RaspberryPi" saved session to load those settings and click Save again.
  15. We should be ready, click Open. If you get a prompt click on Yes. Other than that, you should have the same outcome as the OpenSSH way. To close the SSH, type exit.

PuTTy inside Cmder

If you are using Cmder, you can add your PuTTY connection to your Pi to your list of predefined tasks.

  1. Open Cmder.
  2. Window Key + Alt + T to open ConEmu's Settings in the Startup > Task tab.
  3. Click on the + to add a new Predefined Task
  4. Name your task something like "Putty::RaspberryPi"
  5. Make sure the "Taskbar jump lists" is the only checkbox checked.
  6. You do not need to apply any task parameters, but you do need to write a command. In the command field, write
putty.exe -new_console:t:"RaspberryPi" -load "RaspberryPi"

This should be the only line in that command. DO NOT PRESS ENTER! It will add another line at the end and ConEmu will assume you want to open a second terminal. We don't want that!

  1. Use the Up and Down buttons to move the task with similar Putty task if you have them.
  2. Click on Save settings.
  3. When you click on the green plus sign to open an menu to create a new console, go to the Putty item and select RaspberryPi. If all goes well, you'll be able to use you Raspberry Pi in that program.

Links

Setup

  1. [Assemble the Hardware](Assemble the Hardware)
  2. [Install the Software](Install the Software)
  3. 🆙 [Setup your Raspberry Pi](Setup your Raspberry Pi)
  4. [Download the Missing Parts](Download the Missing Parts)

Typical Utilities

  • [Downloading and extracting with curl and tar](curl and tar)
  • [Browsing with ls and cat](ls and cat)
  • [Searching with grep and find](grep and find)
  • [Filtering with sed and awk](sed and awk)
  • [Piping with less, pv, and tee](less, pv, and tee)
  • Monitor your system with htop
  • Multiplex with tmux

Clone this wiki locally