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)
– Computer with Ethernet port & SD Card slot
– SD Card (8GB or larger)
For this project, you’ll need the following (free!) software programs:
- To write the Raspbian OS to the SD Card (and also format the SD card)
- Bonjour Print Services (install for Windows or Linux OS only)
- For using the “raspberrypi.local” IP address
- To SSH into the Pi
- Remote Desktop Connection (install on non-Windows computers)
- For running the GUI via SSH
Configure the SD Card
1. Download your favorite flavor of Raspbian! You can get the most recent version here.
2. Insert your SD card 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.
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.
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).
Linux Hot Keys!
There are a handful of special key combinations that make navigating the terminal window easier and faster. Here are a some of the most common ones:
- Ctrl+A – Move cursor to beginning of command line
- Ctrl+E – Move cursor to end of command line
- Ctrl+C – End running program
- Ctrl+D – Logout of current session
- Ctrl+R – Search command history
- Ctrl+Z – Suspend a program
- Left and Right arrow keys – Move cursor one place to the left or right on command line
- Up and Down arrow keys – Browse command history
- Shift+PageUp and Shift+PageDown – Browse terminal buffer (to see text that is off screen)
- Tab – Command or filename completion
- Tab Tab – Shows file or command completion options
Practice using these every time you are in the terminal window and you’ll quickly become a Linux wizard!
Getting Help in the Terminal
1. Manual and Information 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:
This will pull up the manual pages for the particular command that you are searching. Here’s the manual pages for the apropos command:
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 info pages contain more recent information and can be easier to use. Here’s what the menu of the info pages looks like:
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.
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.
Here’s the apropos search results for “text”, which displays commands and programs that contain the phrase “text”:
3. Using the –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):
The output looks like this:
Enough of the Terminal Window! Where’s the friggin’ 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.)
Now you can use the Pi’s GUI and do almost* everything via your PC!
*Sadly, we can’t play Minecraft in this mode as it uses too much data to be transferred via SSH. Using a VNC viewer is one option around this if you really want to play Minecraft remotely.
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!
More to Explore!
Go forth and explore! Practice using the terminal window until you get comfortable and familiar with the basic commands.
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 🙂