[Ok] Enable SSH to Raspbian Jessie (Lite) without a monitor


7 posts
by rtek1000 » Mon Mar 28, 2016 5:33 pm
Use a computer with linux and edit the /etc/rc.local file on RPi SD card:
(tested with Xubuntu 15.10 LiveCD not need install)

a. Create a empty file called etc/SSHFLAG (just open and save)
(Xubuntu: sudo mousepad /etc/SSHFLAG)

b. Insert the following code into etc/rc.local just above the exit 0 line.
(Xubuntu: sudo mousepad /etc/rc.local)

Code: Select all
if [ -e /etc/SSHFLAG ]; then
  /usr/sbin/update-rc.d -f ssh defaults
  /bin/rm /etc/SSHFLAG
  /sbin/shutdown -r now
fi

c. Save file and put SD card on RPi

d. After boot, wait RPi make one auto restart (maybe two minutes) after this can you ping to IP of RPi, if is ok, power off RPi and edit again file /etc/rc.local with computer

Now insert the following code into etc/rc.local just above the exit 0 line.
Code: Select all
sudo /etc/init.d/ssh start

e. Save file and put SD card on RPi

d. After boot, ping to IP of RPi, if is ok, try login with ssh client (putty or other)

It is all.

Sources:
http://raspberrypi.stackexchange.com/qu ... spi-config
http://www.raspberrypi-spy.co.uk/2012/0 ... pberry-pi/
Posts: 19
Joined: Wed Mar 12, 2014 9:21 pm
by DirkS » Mon Mar 28, 2016 11:20 pm
rtek1000 wrote:It is all.

It's too much.
On Raspbian Jessie (full and lite) the SSH daemon is enabled by default...
Posts: 6559
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK
by drask » Mon Nov 28, 2016 5:01 am
Actually, I am using 2016-05-27-raspbian-jessie-lite.img (I run apt-get update/upgrade right after I install it) and every time I have installed with it, I have had to enable ssh. I don't know if every lite image is like this, but this one definitely seems to be. It's pretty annoying since I always run these headless and log in. These instructions are a great help. When I'm setting up a new pi now, I extract the filesystem onto the SD card, then cd to the etc directory on the sd card and set up my wireless using:

Code: Select all
sudo wpa_passphrase "<my wireless network>" >> wpa_supplicant/wpa_supplicant.conf


so it's easy to do this at the same time.

I changed the script so you don't have to modify the files the second time:

Code: Select all
if [ -e /etc/SSHFLAG ]; then
  /usr/sbin/update-rc.d -f ssh defaults
  /bin/rm /etc/SSHFLAG
  /sbin/shutdown -r now
else
  /etc/init.d/ssh start
fi


It probably would be better to just go ahead and use systemd rather than continue to use the sysV commands:

Code: Select all
if [ -e /etc/SSHFLAG ]; then
  /bin/systemctl enable sshd
  /bin/rm /etc/SSHFLAG
  /sbin/shutdown -r now
fi
Posts: 2
Joined: Sun Nov 27, 2016 7:21 pm
by pirich » Fri Dec 16, 2016 11:11 am
Thank you! - This last snippet works like a charm except that 'sshd' should be 'ssh'.
Posts: 1
Joined: Fri Dec 16, 2016 11:09 am
by nsotnikov » Wed Dec 28, 2016 11:37 pm
Now it's very simple.

If you want to enable SSH, all you need to do is to put a file called ssh in the /boot/ directory.

Thats all. And don't forget to change the password.
Posts: 1
Joined: Wed Dec 28, 2016 11:33 pm
by giuse320 » Mon Jan 09, 2017 7:19 pm
by nsotnikov » Wed Dec 28, 2016 11:37 pm
Now it's very simple.

If you want to enable SSH, all you need to do is to put a file called ssh in the /boot/ directory.

Thats all. And don't forget to change the password.



This works for me , thanks nsotnikov!
Posts: 1
Joined: Mon Jan 09, 2017 7:17 pm
by drask » Sun Jan 15, 2017 4:49 am
pirich wrote:Thank you! - This last snippet works like a charm except that 'sshd' should be 'ssh'.


Oops, sorry. I knew I should have tried that before I posted it. That ssh/d thing gets me every time.

Also, the wpa_passphrase line should be
Code: Select all
sudo su -c 'wpa_passphrase "<my network name>" >> wpa_supplicant/wpa_supplicant.conf'

otherwise you will most likely get a "permission denied" error since the sudo only affects the wpa_passphrase command and not the redirect.

Just tried this with 2017-01-11-raspbian-jessie.img (the latest Pixel desktop version) and still found that ssh is not enabled by default.

Pulled the plug (the machine is connected to a small monitor but not to a keyboard or mouse), put the SD card back in my main computer, cd'd to the boot directory on the sd card and did a
Code: Select all
sudo touch ./ssh
and the next time ssh was enabled, as evidenced by helpful warnings that running with the default password and ssh enabled is probably not the smartest thing to do. Thanks for the tip, nsotnikov, it works well.
Posts: 2
Joined: Sun Nov 27, 2016 7:21 pm