How to Set Up A Raspberry Pi Headless - Deep Dive
This is a great exercise even if you don't need to set up your Raspberry Pi Headless. It's good experience and you'll pick up some tips and tricks hopefully and get a deeper understanding. We show you using a Mac, Windows PC, Smartphone, and Tablet.
- What Is Headless?
- Video Walkthrough
- Find The Address Of Your Raspberry Pi
- Ping Your Pi Is It Alive
- Try Connect To Your Raspberry Pi Using SSH
- Enable SSH On Your Headless Pi
- Connect To Your Raspberry Pi Using SSH
- Find Out Who Is On Your Pi
- Connect Using Smartphone Or Tablet
What Is Headless?
Headless means no monitor, mouse or sometimes even a keyboard. We'll show you how to connect to your Raspberry Pi from another computer, tablet or phone. This can be a very cheap option, or handy when you have multiple Pis.
Our Web Server is a headless Raspberry Pi, it only has power, a USB HD, and a network cable attached. No keyboard, monitor or mouse.
Find The Address Of Your Raspberry Pi
You can easily find your IP Address if you are on your computer but we are headless so what do we do?
We used to use the admin tool of our router to list all the devices connected to it. All routers will have this functionality, and you can use this to find the IP Address of your Raspberry Pi. It will look something like this 192.168.1.10
There is now an easier way to do this, which before you would have to set up yourself. You can use hostname.local instead of the IP address. A fresh install of Raspbian will have a hostname raspberrypi so you can use raspberrypi.local instead of it's local IP Address.
If you've changed your host name then use that instead of raspberrypi.
Ping Your Pi Is It Alive
Once you have your IP Address you can open a terminal/shell and ping it.
You can use the IP or the raspberrypi.local and press ctrl-c to stop pinging.
ping 192.168.1.10 PING 192.168.1.10 (192.168.1.10) 56(84) bytes of data. 64 bytes from 192.168.1.10: icmp_seq=1 ttl=64 time=0.246 ms 64 bytes from 192.168.1.10: icmp_seq=2 ttl=64 time=0.177 ms 64 bytes from 192.168.1.10: icmp_seq=3 ttl=64 time=0.179 ms ^C --- 192.168.1.10 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2084ms rtt min/avg/max/mdev = 0.177/0.200/0.246/0.032 ms
Try Connect To Your Raspberry Pi Using SSH
Using a terminal/shell we can open a SSH (secure shell) session. We type ssh XXX@YYY where XXX is your username and YYY is the address of your Raspberry Pi.
In the past we could do this right off the bat but for security reasons this doesn't work any more without a few extra steps. So if we try.
ssh email@example.com ssh: connect to host raspberrypi.local port 22: Connection refused
Our ssh connection was refused. This is because a fresh install of Raspbian will have a known hostname (raspberrypi.local) and password (raspberry) so anyone with network access can SSH to it and someone may have evil intentions!
Enable SSH On Your Headless Pi
SSH is disabled by default, with access to the Pi we can go in and change that in the configuration but again we are headless so what do we do?
Shutdown the Pi, take out the SD card and mount it onto another computer. The drive should be mounted as a drive called boot and you will see a list of files. They will have extensions like .dtb, .dat, .elf, .img.
Simply save a new file to this drive and make sure the filename is ssh.
So many ways to create a new file but we were on a Mac so used the shell command touch.
Now unmount and eject the SSD card, put it back into the Pi, reboot and SSH should be enabled. Your 1st task should be to change your password.
Connect To Your Raspberry Pi Using SSH
Now open a terminal/shell and you should be able to connect via SSH. You will get a ECDSA key fingerprint warning, enter yes and then you should be prompted for your password.
ssh firstname.lastname@example.org The authenticity of host 'raspberrypi.local (192.168.1.14)' can't be established. ECDSA key fingerprint is SHA256:wtb/JLnX2lOqy8SpYwdbU5Hl1vQ9GW3IPKCv4z/WkEQ. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'raspberrypi.local,192.168.1.14' (ECDSA) to the list of known hosts. email@example.com's password: Linux raspberrypi 5.4.83-v7l+ #1379 SMP Mon Dec 14 13:11:54 GMT 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Wed Oct 27 16:32:18 2021 SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
Now you are connected to your headless Pi and can do anything you like. Probably a good idea to change that password, when you want to leave simply type exit.
exit logout Connection to raspberrypi.local closed.
Find Out Who Is On Your Pi
Once you have a SSH session you can type in commands. In the video we use the top, ls, and who.
who will list everyone logged onto the Pi
who pi tty7 2021-10-27 16:32 (:0) pi tty1 2021-10-27 16:32 pi pts/0 2021-11-01 17:02 (192.168.1.10)
Connect Using Smartphone Or Tablet
We found many free Apps by searching for SSH in the app stores of various devices. We wound up using Terminus - SHH client but there a many out there.
Each App will be different but we just used the same SSH details as we did for the way we did this with a shell session. We found using the hostname.local didn't work so used the IP Address instead.