Sharing wifi with a raspberry pi zero w using create_ap

I had a bit of a chicken and egg situation while connecting a raspberry pi zero w to wifi. I work on a ship for six weeks at a time, so my choice of wifi is limited to the cabin network on the ship. This has a two part authentication. First, a password is used to connect to the wifi. Then a user ID and a different password is entered into a login page on a browser. My pi zero w has the lite version of the raspbian operating system. No GUI. No browser. I ssh into it, connecting the pi to my laptop with a USB cable.

Top tip number one – you cannot ssh into the pi zero w if the usb cable is connected between the port labelled pwr (power) on the pi. You need to use the other port.

There are plenty of good sites telling you how to set up the pi zero w to connect with your laptop via ssh by doctoring a couple of files on the micro SD card housing your raspbian OS. There are plenty of sites telling you how to setup a wifi connection using linux. I could get the little pi onto the ship’s wifi, but I could not complete the second stage of browser based authentication as there is no browser on the lite version of the OS. There are text based browsers available for Linux, which would enable me to complete the second stage of the login. But I could not install one of these as I did not have a connection to the internet. I am on a ship remember, no other wifi is available.

So I shared my laptop’s wifi with the pi zero. I use Linux. To share my wifi I used the create_ap library. To set up a new wifi link from your laptop:

sudo create_ap wlan0 wlan0 <new wifi name> <password>

e.g.

sudo create_ap wlan0 wlan0 my_wifi my_password

ssh into your raspberry pi:

ssh pi@raspberrypi.local -p22

If this does not work, try:
nm-applet
Edit wired connection 2 (or whichever is the highest numbered ‘wired connection’. Go to the IPv4 Settings tab. Select Link-Local Only for the method.
After ssh’ing into your pi, check that you can see your new wifi from it:

iwlist scan | grep my_wifi 

Now enter details of your new wifi into the wpa_supplicant.conf file:

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

Enter this:

network={
        ssid="my_wifi"
        psk="my_password"
}

If an error about authentication is received – go to a browser in the host laptop and log in to the local wifi that is being shared to ensure that it is active.

Now you should have wifi access from your pi.