User avatar
bgowland
Posts: 8
Joined: Thu Dec 24, 2015 3:00 pm
Location: West Yorkshire, UK

HOWTO: Configure headless Pi Zero for secure wifi connection

Thu Dec 24, 2015 9:37 pm

I don't have a wireless keyboard/mouse or a monitor I can conveniently connect my Pi Zero to but that's OK, I want it headless anyway running VNC server...but how to get Tight VNC Server set up without a network connection in the first place?

I'm not a Linux or RPi expert but knew basically what I was looking for and in the end it was more straightforward than I thought it might be. I though I'd share here.

I used the following steps on my Debian Wheezy desktop...

1. Downloaded and unzipped Raspian Jesse image then wrote the image to the SD card.
2. Found the main partition of the SD card as follows...

Start Root Terminal and execute the following...
df
This will give information about all filesystems. In my case the two partitions show as...
...
/dev/sdb2 3717172 3427252 101096 98% /media/ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202
/dev/sdb1 61384 20296 41088 34% /media/boot
...
It's the one with what looks like the GUID name that I wanted as this contains the core Linux files. The key file I wanted is /etc/wpa_supplicant/wpa_supplicant.conf but file permissions need to be changed in order to edit it.

3. At Root Terminal type...
cd /media/ad6203a1-ec50-4f44-a1c0-e6c3dd4c9202/etc
chmod 777 ./wpa_supplicant
chmod 777 ./wpa_supplicant/wpa_supplicant.conf
4. I chose to edit the file with gEdit but obviously any text editor will do. The default wpa_supplicant.conf looks like this...
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
5. Now I added a network section...
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="MyRouterSSID"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="abcdefgh"
}
In the above the 'ssid=' and 'psk=' entries need to be set accordingly (obviously). Also, if you need a different security setup, wpa_supplicant.conf is well documented if you search Google and also has its own Linux man page.

That's it. Save the file and don't forget to reset the original file and directory permissions...
chmod 600 ./wpa_supplicant/wpa_supplicant.conf
chmod 755 ./wpa_supplicant
After that I just powered up the Pi Zero with my USB wifi dongle fitted, checked my router for the IP address and then connected in using ssh and could then install Tight VNC Server.

Cheers,
Brian

User avatar
aelsas
Posts: 64
Joined: Fri Jul 06, 2012 11:23 pm
Location: Frankfurt, Germany
Contact: Website

Re: HOWTO: Configure headless Pi Zero for secure wifi connec

Fri Dec 25, 2015 12:48 am

Maybe you should add that you are doing this all on a second computer ... might be confusing for beginners if not ;-)

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: HOWTO: Configure headless Pi Zero for secure wifi connec

Fri Dec 25, 2015 1:38 am

aelsas wrote:Maybe you should add that you are doing this all on a second computer ... might be confusing for beginners if not ;-)
And a *nix one as well, so of limited use for Windows users.

User avatar
bgowland
Posts: 8
Joined: Thu Dec 24, 2015 3:00 pm
Location: West Yorkshire, UK

Re: HOWTO: Configure headless Pi Zero for secure wifi connec

Fri Dec 25, 2015 4:23 am

aelsas wrote:Maybe you should add that you are doing this all on a second computer ... might be confusing for beginners if not ;-)
I did say in the post I'm using a Debian desktop - perhaps that wasn't clear enough. I'll edit the post to clarify it.

Cheers,
Brian

User avatar
bgowland
Posts: 8
Joined: Thu Dec 24, 2015 3:00 pm
Location: West Yorkshire, UK

Re: HOWTO: Configure headless Pi Zero for secure wifi connec

Fri Dec 25, 2015 4:25 am

asandford wrote:
aelsas wrote:Maybe you should add that you are doing this all on a second computer ... might be confusing for beginners if not ;-)
And a *nix one as well, so of limited use for Windows users.
Yep, couldn't work out how to read the main partition using my Windows computer. I know I've got a tool for that somewhere - I'll look closer tomorrow and update my post to cover using Windows.

Cheers,
Brian

User avatar
procount
Posts: 2211
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: HOWTO: Configure headless Pi Zero for secure wifi connec

Fri Dec 25, 2015 9:09 am

Instead of changing the file permissions, you can just edit the file with 'sudo nano wpa_supplicant.conf' (in a terminal window if you run the gui).
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: HOWTO: Configure headless Pi Zero for secure wifi connec

Fri Dec 25, 2015 9:20 am

If you have a USB2Serial cable, you can log in to the Zero's console from any computer. If your WiFi adapter is power-hungry, you may need to apply power via micro-USB PWR_IN and not from the serial cable as shown there. Just don't apply power from both sources at the same time.

Then follow the instructions on page 20 of MagPi 40

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5622
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: HOWTO: Configure headless Pi Zero for secure wifi connec

Fri Dec 25, 2015 9:42 am

gregeric wrote:If you have a USB2Serial cable, you can log in to the Zero's console from any computer. If your WiFi adapter is power-hungry, you may need to apply power via micro-USB PWR_IN and not from the serial cable as shown there. Just don't apply power from both sources at the same time.
...
+1 and I (as the O.P. of the thread linked to) can confirm that a (250mA) USB-to-LAN (wired) adapter can be powered (I haven't, yet. updated my webpages to show this) which implies that the "official", broadcom WiFi adapters (200mA devices)** should work that way too (in my "to do list").
Trev.
** http://www.cpmspectrepi.webspace.virgin ... pters.html
http://www.cpmspectrepi.webspace.virgin ... ased_Setup ("Powerbank" powered)
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
jjex22
Posts: 153
Joined: Tue Feb 24, 2015 12:41 pm

Re: HOWTO: Configure headless Pi Zero for secure wifi connec

Fri Dec 25, 2015 11:50 pm

Hey bgowland, thanks for making the guide!

The editing of the wireless config is excellent, but do you mind if I make a suggestion about how to navigate to that location as I worry that users stumbling on this guide may not find it that easy to follow the section where you find the root partition of the SD card, particularly if it isn't labelled the same as yours in the output of df. The df command isn't particularly suited to this in my opinion, for example df won't list the partitions if they aren't mounted. It's output also isn't very clear as it's really showing you storage space info, there's a lot of superfluous information there to get lost in. It is more common to use fdisk -l or gparted for a graphical overview. Personally I like lsblk as I think it's by far the easier tool; it's output is a nice tree diagram of disks and partitions, and shows both all partitions, and any corresponding mount points. From this output you can give tips on how to identify the SD card, and maybe add a line to show how to mount the root partition if it isn't already mounted.

It also occurs to me that you shouldn't need to edit the permissions of the file if you are in a root terminal? Sudo versus root is an age old debate so I'll let you make the call on that one, but as the only step here that needs root privileges is editing the files, I'd recommend switching to root only when you actually edit the file and then include a line to switch back out of root - just in case a newer user finds the guide and leaves their terminal signed in as root, potentially for days.

Just a couple of suggestions, as I say great guide and thanks for shaing :D

Jim
I had the idea for a single board computer in every seat on airplanes... but it all just seemed a bit Pi in the Sky!

Return to “General discussion”