Enable ssh on a headless Raspberry Pi
Since version 2016-11-25 of Raspbian the ssh daemon is disabled by default (see the Raspbian release notes). But the Raspbian documentation on ssh describes a way how you can enable it again. You can do that before you even copy the image to an SD card and boot for the first time. This comes in handy especially when you run your Raspberry Pi without a monitor or keyboard attached (headless).
Here is what you need to do:
- download the latest Raspbian image, e.g. 2017-02-16-raspbian-jessie-lite.img
- examine the image using fdisk
$ fdisk -l 2017-02-16-raspbian-jessie-lite.img
Disk 2017-02-16-raspbian-jessie-lite.img: 1,3 GiB, 1437597696 bytes, 2807808 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: 0xdbcc7ab3
Device Boot Start End Sectors Size Id Type
2017-02-16-raspbian-jessie-lite.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
2017-02-16-raspbian-jessie-lite.img2 137216 2807807 2670592 1,3G 83 Linux
- in order to mount the boot partition we need to know its start offset in bytes, in our case that would be 512 * 8192 = 4194304
- create a temporary folder to mount Raspbian’s boot partition
$ mkdir mnt
- mount Raspbian’s boot partition
$ sudo mount -v -o offset=4194304 -t vfat 2017-02-16-raspbian-jessie-lite.img mnt
- create ssh file to tell Raspbian to enable the ssh daemon by default
$ sudo touch mnt/ssh
- unmount the partition again
$ sudo umount mnt
- copy the image file to an SD card
- boot your Raspberry Pi, the ssh daemon should be enabled by default