I have a laptop, a power cable, an sd card, and a Pi3 (wifi built in).

I'm trying to ssh in but first I need to setup the wifi. Where on the boot partition can I setup wifi (cmdline.txt?) with a hostname and a password?

  • It will be complicated if you use cmdline.txt. I suggest firing up a Linux virtual machine and editing the /etc/wpa_supplicant/wpa_supplicant.conf file on the Pi's SD card from there. Let me know if you need the cmdline.txt approach or if this will suffice.
    – Aloha
    Commented May 16, 2016 at 0:27
  • well, I managed to get in using another method, so I guess it's fine. I find it strange how inconvenient it is to set this all up.
    – Seph Reed
    Commented May 16, 2016 at 0:40
  • I mean, once it gets running it's amazing. The first step always feels more like hacking than anything.
    – Seph Reed
    Commented May 16, 2016 at 0:57
  • @Seph You should think about writing up your solution, and then accepting it. Might help someone in the future.
    – user44926
    Commented May 17, 2016 at 19:25
  • 1
    thanks, but I used an ethernet to connect to my router. It's nothing like the solution I was looking for
    – Seph Reed
    Commented May 17, 2016 at 21:22

1 Answer 1


Since you have not mentioned some details I think are relevant to the answer such as

  • what OS you are running on PI (which supports many)
  • OS running on the remote machine from which you want to ssh in from,

I will assume the following

PI: raspbian/jessie which the latest as of this writing

Remote: some flavor of linux

This is how I'd go about setting up the customized image from the remote machine

  • download the official raspbian OS image file which should come bundled with the required drivers, firmware compatible with the included kernel.


  • unzip the archive to extract img file. lets call this image file jessie.img for this post

  • the jessie.img file should contain 2 partitions - one for boot (FAT32) and for the rest (EXT4)

  • use fdisk to find out the file offsets of the partitions.

  • we are interested in the offset of the EXT4 partition which contains the root file system
  • here is a sample o/p

fdisk -l ./jessie.img

Disk ./jessie.img: 4.1 GiB, 4348444672 bytes, 8493056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd94ffdb3

Device        Boot  Start     End Sectors Size Id Type
./jessie.img1        8192  137215  129024  63M  c W95 FAT32 (LBA)
./jessie.img2      137216 8493055 8355840   4G 83 Linux

  • here jessie.img2 starts at block 137216 with each block 512 bytes long. so the total offset is the product of the two = 70254592 bytes

  • next step is mount the jessie.img2 as read/write so that we can edit the /etc/network/interfaces

  • make a temporary mount point

mkdir ~/mntpt

  • mount the partition

sudo mount -o loop,rw,offset=70254592 jessie.img ./mntpt

  • change directory to the mount point and verify the required folder exist

cd ./mntpt

bin  boot  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

  • change directory to etc

cd ./etc

  • verify the interfaces file is setup properly

less ./network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

  • edit the /etc/wpa_supplicant/wpa_supplicant.conf file and add the new lines, customize to match your setup, save and exit

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf


  • go back two folders from etc

cd ..
cd ..

  • unmount the image

sudo unmount ./mntpt

  • now the image should be ready to be written out to the disk and booted up



  • there are number of other tools such as parted which also provides the same information as fdisk
  • kpartx makes it bit easier to mount the individual partitions

  • Since this technique requires some unix/linux tools, it might be harder to do the same from a windows machine. a mingw / cgywin setup might work but i have not tried them

  • if you spot any mistakes or encounter any error messages along the way, please leave a comment and I will try to address them the best I can

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.