Introduction: Intro to the (Headless) Raspberry Pi
Finally! Use your Raspberry Pi without spending what feels like forever connecting external peripherals and dealing w/ a cable monstrosity: Configure your Pi to be headless! (not the scary kind tho) This is particularly helpful for folks teaching workshops with the Raspberry Pi, since it can be cumbersome (and expensive) to provide monitors, keyboards, and mice for every student.
I'm assuming that y'all know a bit about the Pi, so this tutorial will not cover what the Pi is or it's awesome capabilities (I'm lookin' at you, GPIO pins!). To learn more about what the Pi can do, check out some of my other tutorials (see the last section in this tutorial) or leave a comment.
What is covered in this tutorial: Enabling and using SSH, a general overview of the Linux terminal window, and how to connect to the Pi's GUI (Graphical User Interface, aka the Desktop view) via SSH.
Read Time: 15 min
Build Time: ~20 min
Cost: Free! (assuming you already have an RPi and Ethernet cable)
Step 1: Materials
Step 2: Software
For this project, you'll need the following (free!) software programs:
Step 3: Configure the SD Card
1. Download your favorite flavor of Raspbian! You can get the most recent version here.
2. Insert the SD card into your PC and open Etcher.
3. Select the Raspbian zip file, the driver for your SD card, and click "format".
4. Enable SSH access
Open the file contents for the SD card. Add a new text file titled "SSH". If the computer adds a file extension (e.g. ".txt"), delete it and ignore any warnings.
5. Eject the SD card and insert it into your Pi.
Step 4: Let's Get Connected!
1. Plug in the Ethernet cable between the Raspberry Pi & your computer.
2. Plug in the USB power cable.
Check that the red power light turns on and that the Ethernet port lights (yellow & green) are on and/or blinking.
3. Connect the RPi to the World Wide Web (aka the Internet).
Go to Settings -> Network & Internet -> Change Adapter Options (aka Network Connections).
Click on the Ethernet connection, hold down "CTRL", and THEN click on your WiFi connection.* Right-click in the window and select "Bridge Connections" -- this will bridge the connection between the Ethernet port to your WiFi port.
*If you select the WiFi connection first, it will bridge the connection from the WiFi to the Ethernet, which would allow you to log into the Pi but not connect to the Internet.
4. Open PuTTY and log in to the Pi using the "raspberrypi.local" IP address.
Default username: pi
Default password: raspberry
5. Change the default password by typing passwd and following the prompts.
Step 5: Navigating the Linux Terminal Window (Shell)
The terminal window is the control panel for the system.
It typically shows a command prompt, which gives us information but is not part of the commands to the system. Most commonly the command prompt displays the user's login name and the current working directory (represented by a twiddle: ~ ).
Commands are written after the prompt and inputted by pressing the Enter key.
Commands can be issued as-is or followed by one or more options. Options usually have a dash in front of them, like the following:
You can view the options for a specific command by typing the command name followed by "--help" (will cover this more later).
The second photo shows a list of common commands. Practice using them by (1) navigating to the Desktop, (2) creating a file with some text, and (3) saving the file.
Here's a special challenge: type the following command and try to figure out what it is doing.
Step 6: Special Key Combos!
The Linux terminal window is waaay easier (& faster) to use if you know a few special key combinations. The most common include:
- Ctrl+C : End running program
- Ctrl+A : Move to the beginning of the command line
- Ctrl+E : Move to the end of the command line
- Up & Down Arrow keys: Search through command history (can edit these and press Enter to execute again)
- Tab : Filename completion
Check the photos above for a more complete list and practice using these as you navigate the command line!
Step 7: Getting Help in the Terminal #1: Manual & Info Pages
The manual pages are an exhaustive resource for all of the available commands in the Linux terminal window.
To read the manual pages on a particular command, type the following:
In the manual, the first line contains the name of the command you are reading about and the ID of the section that contains the manual page.
After the first line is a synopsis, which is a short description of the command that includes technical notation of all the options and/or arguments. Options are a way of executing the command, and an argument is what you execute it on. Optional arguments are put between square brackets.
After the synopsis is a longer description of the command, followed by a more in-depth overview of the available options, information about combining options, other related commands, and other information pertaining to the command.
Some commands have multiple man pages, like the “passwd” command. To see all pages about a command, use the “-a” option:
man -a passwd
The first section of the manual page for the apropos command is shown in the 2nd photo above.
The info pages contain more recent information and can be easier to use.To view the info pages on a command (replacing "command" with the actual name of the command you want to research, like "apropos"), type the following:
To navigate the info pages, use the arrow keys to browse through text, the Enter key to read about a particular keyword, “P” and “N” keys to go to the previous or next subject, and the space bar to move one page further. Use “Q” to quit.
An excerpt from the info pages is shown in the 3rd photo above.
Step 8: Getting Help #2: Whatis and Apropos Commands
The "whatis" command gives brief information about a command and lists the first section in the man pages that contains a relevant page (in parenthesis after the command name).
If you're entirely unsure where to start, the "apropos" command is a good way to search for keywords. For example, if you want to know how to start a browser, you can type: “apropos browser”, which will pull up a list of all browser-related programs, including web browsers, file and FTP browsers, etc.
Step 9: Getting Help #3: --help Option
Most commands also have the option “--help”, which gives a short explanation of the command and a list of available options. When in doubt, this is a great way to get some quick and useful information on using a particular command and its possible extensions.
To use the --help option, type "--help" after a particular command, like the following example (also shown in the photo above):
Step 10: Enough of the Terminal! Where's the Desktop?!
Alright alright.. Remote Desktop Connection is an easy way to use the desktop view, also known as "Graphical User Interface," or GUI for short.
1. Install Remote Desktop Connection on your Pi:
sudo apt-get install xrdp
2. Install Remote Desktop Connection on your PC (is already installed on Windows OS).
3. Open Remote Desktop Connection and log in using the "raspberrypi.local" IP (or find your Pi's IP using command ifconfig). Ignore warning (click "yes").
4. Log in with the Pi's username and password.
If you haven't changed your password yet, do so now. (Yes, I know I already told ya to do so but it is worth repeating since someone could actually hack into your Pi if you don't change the default password.)
Step 11: What Is SSH, Anyway?
SSH stands for "Secure SHell" -- it is a "cryptographic network protocol for operating network services securely over an unsecured network." - Wikipedia
... Uh, what?
In other words, SSH is a secure way to connect between one computer and another, even if the network through which you are connected is not secure. For example, if you are on a shared network and you use SSH to remotely log into another computer, other folks on the shared network can't see what you're doing through the remote connection (although Snowden did release documents that showed the NSA can sometimes decrypt SSH).
Common uses of SSH include remote log in, like if you want to connect to a computer that lives a mile underground without having to, you know, actually go down there (I used to work for a super cool dark matter experiment called DRIFT and this is how we would access the computers that controlled the detector because the computers lived in a mine about 3 miles underground.. too far to travel to update software!).
Here's the full Wikipedia page on SSH -- it's super cool so check it out!
Step 12: Wield Your Headless Pi & Keep Learning!
Go forth and explore! Practice using the terminal window until you get comfortable and familiar with the basic commands. You could even consider removing the Ethernet cable & making your Pi an access point (I'll be posting a tutorial on this in the next few weeks).
Program the GPIO pins to do cool stuff! Need some ideas? Check out these tutorials:
2. Building an Irrigation Controller (can be paried w/ Soil Moisture Sensor)
4. Expand on your Smart Home & add a Motion Triggered Music Player
Take apart old & broken electronics! Electronic toys are a great place to get motors and speakers. If you want better motors, take apart power tools.
Ask friends or find a repair shop for extra parts and wire, save power cables from old electronics and use them as power supplies or harvest them for wires and/or connectors, save old headphones and use them for audio projects.
Best piece of advice: think before you toss :)