Raspberry Pi is great. It is a small and cheap computer that can be used for a variety of projects. Sometimes you may wish to remotely control a Rasperry Pi that is in your local WiFi network. This is possible and even quite easy.
We will use a Secure Shell aka SSH to establish a remote connection. I assume that you have previously connected your Raspberry Pi board to a WiFi network. I also assume that you are connecting from a Linux or OS X machine.
Step 1: Enable SSH On Raspberry Pi
There are several methods to enable SSH access,
including graphical user interface (GUI).
However, I find the easiest method is without even turning on your Raspi board.
This also does not require any GUI to be installed.
We enable SSH simply by creating a blank
ssh on the Raspbian OS boot partition.
That is on the memory card where Raspbian OS is intalled.
So insert the Raspi SD card in your computer.
Assuming that the SD card maps to two devices1,
/dev/mmcblk0p2, the first of them usually corresponds to the
partition. Below, we mount the partition to an existing directory
/mnt/usbstick. Finally, we create ("touch") a blank file
ssh within the directory.
sudo mount /dev/mmcblk0p1 /mnt/usbstick cd /mnt/usbstick sudo touch ssh
Afterwards, before inserting the memory card back into Raspberry Pi, we unmount the partition:
cd sudo umount /dev/mmcblk0p1
Done. Now, during its boot, Raspbian will find the
and will allow SSH access.
Step 2: Discover IP Address of Raspberry Pi
One way is to boot your Raspi, open terminal and type:
$ hostname -I 192.168.0.13
If this works for you, note the address and skip directly to Step 3. However, if there is no monitor connected to your Raspi board this is not a problem at all. You can discover connected devices on your WiFi network. First, learn your network address range and then scan it for connected devices.
Note that on some machines
ip addrcommand is called
This will provide the information about network interfaces.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 9c:b6:d0:8e:ad:19 brd ff:ff:ff:ff:ff:ff inet 192.168.0.11/24 brd 192.168.0.255 scope global dynamic noprefixroute wlp2s0 valid_lft 85985sec preferred_lft 85985sec inet6 fe80::42f4:2e5a:a6b2:9232/64 scope link noprefixroute valid_lft forever preferred_lft forever ...
Our computer has local IP address 192.168.0.11.
Therefore, our WiFi network has IPs starting with
Scan Your WiFi Network
Install nmap using your system's package manager. For example, on Arch Linux:
sudo pacman -S nmap
$ nmap -sn 192.168.0.0/24 ... Nmap done: 256 IP addresses (3 hosts up) scanned in 2.52 seconds
If your Raspi board was off, boot it now, wait until it connects and scan the network again.
$ nmap -sn 192.168.0.0/24 Starting Nmap 7.80 ( https://nmap.org ) at 2020-04-25 16:03 CEST Nmap scan report for 192.168.0.1 Host is up (0.044s latency). Nmap scan report for 192.168.0.5 Host is up (0.019s latency). Nmap scan report for 192.168.0.11 Host is up (0.000066s latency). Nmap scan report for 192.168.0.13 Host is up (0.016s latency). Nmap done: 256 IP addresses (4 hosts up) scanned in 2.37 seconds
The newly appeared host is your board.
Step 3: Connect To Raspi
$ ssh email@example.com firstname.lastname@example.org's password: Linux raspberrypi 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 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: Sat Apr 25 16:03:26 2020
Now, we can control the board or even exchange files with
$ pi@raspberrypi:~ $ whoami pi
Hint: do not forget to change the default user password:
sudo passwd pi
dmesg|tailoutput to see the newly connected devices. ^