Introduction: Raspberry Pi Made Easy - Part 2 (running Headless and Loving It)
Some might rightly argue that it is too early in our exploration of the Raspberry Pi (RasPi) to examine running headless; but, if I had known how convenient it is and how many problems it would eliminate, I would have wanted to learn it very early in my own journey of discovery.
Running headless is the term referring to controlling a RasPi (or any other device) remotely from another computer so that you don't need a mouse, keyboard, or even a monitor attached directly to the RasPi. One of the websites at which more on the subject can be found is BitPi.co.
I can't remember the many times I have begun typing instructions to my RasPi and then discovered I was typing on the wrong keyboard; or how many times I tried to click with the mouse and discovered I was using the wrong mouse. Going headless and controlling the RasPi from my PC has left more room on my desk for connected hardware; it has removed a lot of frustration over wasting time using the wrong keyboard or mouse; and it has greatly increased my enjoyment of playing with the RasPi.
Understand, there are more ways to accomplish the headless connection than is reasonable to look at in this instructable. (See the Raspberry Pi Foundation's page on Remote Access.) We could connect by directly cabling from the PC's to the RasPi's Ethernet jacks. While this method provides the best remote security, it distances us from ultimately working on IoT devices. (If you are interested in knowing this method, one of the many sites that describe how to direct cable is Circuit Basics.)
We will examine two methods of connection over networks; yes, the Internet is a network. These two methods are the easiest to set up that I have found.
What We'll Need
RasPi complete with monitor, keyboard, and mouse (I'm using the same Model B from Part 1.)
Micro USB cable for power from your PC.
PC (I'm running Windows 10.)
SD card with Raspian already configured as in Part 1.)
Cabled Internet connection.
Step 1: Getting the RasPi Ready to Go Headless
We have to prepare our RasPi so we still need the connected monitor, keyboard, and mouse for now. When we have completed this instructable, we will no longer need a separate keyboard or mouse. We will still need a monitor if we want to work with multimedia since the RasPi sends played content to its on-board media ports and not to the Ethernet jack.
On the RasPi, open the Terminal and issue the command hostname -I (that's a capital i)(remember to press ENTER after every command.) If you are connected to the Internet, the RasPi will display its IP address. You need this so make a note of it. If it displays nothing, you are not connected to the Internet.
IP addresses are typically assigned by the network router. While it is possible you will get an IP address that changes the next time you connect to the Internet, my experience is that as long as you connect the RasPi to the same jack on the same network, your IP address will likely not change. It is possible to set a "static" (non-changing) IP address, however, that is not a topic for this instructable.
In the Terminal, issue the command sudo raspi-config.Select Advanced Options. Select SSH. SSH (Secure Socket Shell) is a protocol which provides secure remote access to another computer. More can be read about it here.
Select Yes. Select Ok. Select Finish. By enabling SSH, we have given permission for other computers to remotely access/control our RasPi.
This all that needs to be done on the RasPi for access via PuTTY, a text based medium (the topic of Step 2); however, we also want to provide access through a graphical medium (the topic of Step 3) so we must prepare the RasPi for this also and might as well do so now so we can remove its mouse and keyboard after this Step.
In the Terminal, issue the command sudo apt-get install xrdp -y. This command installs a protocol for remote access to a Linux desktop, i.e. our Raspian GUI.
Our RasPi is now ready for remote access.
Step 2: PuTTY Couldn't Be Simpler
We can now remove the keyboard and mouse from our RasPi (it isn't compulsory.) This means that all future interactions can occur on our PC and commands/data will be sent to/from the RasPi if appropriate.
PuTTY is a terminal based SSH and Telnet client which can be downloaded to your PC from here. You want to download putty.exe from the list of available downloads. Because it is an .exe, it requires no installation. I recommend moving it to a location with other program files so it isn't inadvertently deleted at some point during maintenance. I moved it to my C: drive and then pinned it to my Start menu. When I want to use it, I simply click on its icon.
Both the RasPi and your PC must be connected to a network/the Internet for remote access to work as it is presented in this instructable - obviously to separate Ethernet jacks.
Start PuTTY. Enter the RasPi's IP address in the box titled HostName (or IP address). Ensure the Connection type: SSH is selected. I recommend you do not make any other changes. Click the Open button.
If PuTTY finds anything at the IP address you specified, it will ask for a log in. If you have changed the default user name, type it in; if you have not changed the default user name, it is pi.
PuTTY then asks for a password. Type in your password if you changed it; if you didn't change it, the default password is raspberry.
With a successful login, you can now access the RasPi as though you were actually working on it through the Terminal. Since most of the things we will wish to accomplish in the upcoming instructables will be accomplished through the command line, PuTTY is a most convenient remote access tool.
When you are finished with a PuTTY remote access session, and wish to stop using the RasPi, issue the command sudo shutdown -h now. This command powers down of the RasPi immediately.
A note about security.
Anyone can now remotely log into your RasPi if they know its IP address. All they need is the default user name and password. There is little havoc anyone could wreak at this stage other than make us install a fresh Raspian image. As we develop more complex applications on our RasPi, we will want to increase its security by changing the password for the default user. This can be done by issuing the command sudo raspi-config then selecting Change User Password. I am not recommending that you change it at this time; however, if/when you do change it, do not forget it. I consider the risk so minimal that I will not change it at this early stage of our exploration of the RasPi. (I pray no one will take this as a challenge to make me regret not changing it now.)
It is also possible to change the default user to something other than pi; but, that is not a topic of this instructable.
Step 3: I Prefer the GUI
As simple as PuTTY is to implement, there are times when I prefer the same screen I get when I attach a monitor to the RasPi; after all, I could always get the Terminal from the GUI if I wanted it. This where xrdp comes in. We installed it on the RasPi in Step 1 so we can now use it. (Circuit Basics has a page worth reading on xrdphere.)
Windows 10 (I suspect older versions have it also) has a program called Remote Desktop Connection. If you can't find it on your PC, use the search bar next to the Start button. Type in Remote Desktop Connection.
Start the Remote Desktop Connection application. In the window labeled Computer: enter the IP address of your RasPi and click the Connect button.
If Windows finds the RasPi, it responds with a verification error message (apparently xrdp is old and doesn't meet Windows current security standards.) Ignore the message and proceed with the connection by clicking the Connect button.
In the dialog that askes you to provide login information, enter your user name and password. The password with not be visible as alphanumeric characters. Click the OK button. On occasion my login has failed; when it has, I simply entered the same information a second time and it worked fine when I clicked OK.
When the connection is successful, a GUI window will open after a few moments (wait for it.) Except for the mouse cursor shape and possibly the IP address in the title bar, the screen mimics that shown on a monitor connected directly.
From here you can start the Terminal or explore other parts of the GUI.
Step 4: All Done
Your screen should look similar to that is this step. Now you know why the IP address shows in my screen capture title bar whereas it didn't when a monitor was connected to the RasPi.
Congratulations! You can now use remote access to control your RasPi. Among other conveniences, you'll discover that we now are able to do some copying and pasting between the RasPi and the PC - very useful when we start coding in future instructables.
There are other ways to implement remote access. If you have a better/easier way, please let me know. Please leave comments if you have found this instructable useful. Please point out any errors or omissions. Thanks for reading.
This is a good time to update all software on the RasPi in case anything has been improved since initially installed. In the Terminal, issue the command sudo apt-get update, then issue the command sudo apt-get dist-upgrade -y.