Script to enable SSH on Raspbian .img image files

In November 2016, the Raspberry Pi Foundation, quite sensibly, disabled SSH by default on new Raspbian SD card images. This Linux Bash script enables SSH on .img image files, without you having to write to an actual SD card first.


sudo raspbian-image-enable-ssh [ imagefile.img ]

If you ommit imagefile.img , then the latest version of Raspbian Jessie Lite is downloaded.

Download the script - right-click and Save As... then place it in /usr/local/sbin/ , chown root.root , chmod 755 .

Alternatively, directly from the Linux command line (e.g. terminal):

curl -O "" && sudo mv raspbian-image-enable-ssh /usr/local/sbin && sudo chmod 755 /usr/local/sbin/raspbian-image-enable-ssh && sudo chown root.root /usr/local/sbin/raspbian-image-enable-ssh

The script works by simply adding an empty file called "ssh" into the /boot/ directory of the image. You can find out more about mounting images as a loopback device.

As per the security update blog post, it is best practice to change the password for the Pi user if you enable SSH on a device open to the public. However there are a few edge cases when you might want to ignore that advice - for example if you're mass duplicating cards to follow a tutorial in a classroom for one afternoon only. Make sure you understand the implications if you do so - reading the security update article is a good start.

Like this utility? It's public domain, so copy and change it at will. Consider donating to Cotswold Raspberry Jam, the child-focussed Raspberry Pi coding & project club that I run in Gloucestershire.

Public Domain - Andrew Oakley - 2016-12-05

Top - More Computing Articles - Article Index -