I have seen a lot of guides to configure headless operations without attached display, keyboard, and mouse - all of which seem to be out of date.  Maybe it's because that Raspbian has evolved or something else.  Anyways, this technote is based on Raspbian Stretch or Stretch-Lite circa September 2017.

 

I got this Raspberry Pi Zero "W" for USD 5.00 by walking into a local store (http://www.microcenter.com/product/486575/Zero_W) in the Dallas/Fort Worth Texas USA area.  That price is for one.  If you want more, then the unit price goes up - sort of a volume "anti-discount" .  They also have a USD 5.00 price on the "official" Pi zero case.  Unfortunately, you have to walk-in as I was told.  There must be other stores around the 3rd rock that offer comparable discounts (UK? Hong Kong? Rotterdam?).

 

I'll assume that the reader has just created a MicroSD Raspbian installation in the usual manner on the workstation.  Make sure no writes are pending.  If the 2 Stretch partitions are not yet automounted, pull out the caddy and push it back in.  This should cause an automount of the 2 Stretch partitions of the MicroSD.

 

On my Linux system, `sudo blkid` shows the following after creating the Raspbian boot MicroSD:

 

/dev/sdc1: LABEL="boot" UUID="E5B7-FEA1" TYPE="vfat" PARTUUID="020c3677-01"

/dev/sdc2: UUID="b4ea8e46-fe87-4ddd-9e94-506c37005ac5" TYPE="ext4" PARTUUID="020c3677-02"

 

with corresponding mounts

 

/media/USER-NAME/boot/

/media/USER-NAME/b4ea8e46-fe87-4ddd-9e94-506c37005ac5/

 

Enable SSH on the first Raspbian power-up

 

cd /media/USER-NAME/boot/

touch ./ssh

 

Assuming that you are using Wifi, enable the connection.  The following is an example on my Linux system for the USA using WPA-PSK security.

 

cd /media/USER-NAME/b4ea8e46-fe87-4ddd-9e94-506c37005ac5/etc/wpa_supplicant

sudo vi  wpa_supplicant.conf

 

Replace the existing contents of wpa_supplicant.conf with the following:

 

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

country=US

 

network={

ssid="Your network SSID"

psk="Your WPA/WPA2 security key"

key_mgmt=WPA-PSK

}

 

I highly recommend setting up a static IP address; this is very convenient for headless SSH operation.

 

Assuming that:

 

    1. You are using Wifi and your wireless device is named wlan0
    2. The desired IP address for the Raspberry Pi = 192.168.1.104
    3. The router IP address = 192.168.1.1
    4. The primary DNS server is also at 192.168.1.1

 

append to /etc/dhcpcd.conf the following:

 

interface wlan0

static ip_address=192.168.1.104/24

static routers=192.168.1.1

static domain_name_servers=192.168.1.1 8.8.8.8

 

Adjust IP addresses as necessary for your environment.

 

Note that if you are using wired Ethernet instead of Wifi and its device name is eth0, then specify this interface instead:

 

interface eth0

 

Be sure to sync; sync; sync changes to the MicroSD before removing it from the USB port.

 

Insert the MicroSD into the Raspberry Pi and power up.

 

From your workstation, connect to the Pi

 

ssh -X pi@PI-IP-ADDRESS   # -X allows me to invoke X GUI programs like the Gnu text editor (`gedit`)

 

Change the root password to something that you'll remember, just in case

 

Configure the Pi

sudo raspi-config

 

  1. Change password for user pi
  2. Localisation - Language and Regional settings
  3. Timezone - Where are you?
  4. If you already have a Raspberry Pi with host name "raspberrypi", you will probably want to change this Pi Zero W's host name to something else.
  5. Reboot

 

On your workstation, I would enter the host name and static IP address for the Raspberry Pi in /etc/hosts (assuming the workstation is Linux or Unix).

 

From your workstation, connect to the Pi

 

ssh pi@PI-HOST-NAME

 

Got an NFS file server that the user "pi" needs access to on a permanent basis?  Permanently mount "/mnt/bigtree.nfs"

 

1. I'll assume that your NFS server is set-up and you know how to manage it.  Practical overviews of NFS set-up can be found here:

Be sure to read the comments too.  All of us have learned NFS at the "School of Hard Knocks" but it is worth it.

 

2. Set up a local mount location:

 

cd /mnt; sudo mkdir bigtree.nfs; sudo chown pi:pi bigtree.nfs

 

3. Append the following to /etc/fstab; adjust per your local requirements:

 

# Mount bigtree.nfs using NFS

# NFS-SERVER is the host name as specified in /etc/hosts (static IP address).

# This NFS server has "bigtree" rooted directly under mounted file system "/data4188".

NFS-SERVER:/data4188/bigtree   /mnt/bigtree.nfs   nfs   rw,bg,auto,noatime   0   0

 

4. Test (In general, always test immediately after making system changes!):

 

sudo mount -a

touch /mnt/bigtree.nfs/xx

rm /mnt/bigtree.nfs/xx

 

Got a SAMBA file server that the user "pi" needs access to on a permanent basis?  Permanently mount "/mnt/bigtree.samba" as follows:

 

1. I'll assume that your SAMBA server is set-up and you know how to manage it.

 

2. Set up a local mount location:

 

cd /mnt; sudo mkdir bigtree.samba; sudo chown pi:pi bigtree.samba

 

3. Append the following to /etc/fstab:

 

# Mount bigtree using SAMBA

# SAMBA-SERVER is the host name as specified in /etc/hosts (static IP address).

# This SAMBA server has a share named "bigtree".

//SAMBA-SERVER/bigtree /mnt/bigtree.samba cifs auto,owner,rw,credentials=/root/bigtree.credentials,uid=pi,gid=pi 0 0

 

4. Create /root/bigtree.credentials for the login to the SAMBA server (read and write access):

 

username=SAMBA-USER-ID

password=SAMBA-USER-PASSWORD

 

5. Test mounting changes (In general, always test immediately after making system changes!):

 

sudo mount -a

touch /mnt/bigtree.samba/xx

rm /mnt/bigtree.samba/xx

 

Now is a good time to update your system

 

sudo apt-get -y update

sudo apt-get -y dist-upgrade

sudo apt-get -y autoclean

sudo apt-get -y autoremove

sudo reboot

 

That's it

 

Find any bugs?  Suggestions for improvement?

Richard Elkins

Dallas, Texas, USA, 3rd Rock, Sol