11

A similar question has been asked before: How to set up Raspberry Pi without a monitor?

However, given that the accepted answer doesn't appear to offer an appropriate solution, and given that there's a level of ambiguity in what was being asked, I'm assuming that the original question was mis-constructed, and that my question isn't an exact duplicate.

I'm performing the initial, first-time set-up of a Pi. I don't have a monitor or keyboard, but instead want to use a connected laptop to do the job. I don't want to buy a monitor or keyboard and have them sitting around just for the occasions when they're needed by the Pi. I could borrow them, but I plan to buy more Pi's in the future, and don't want to have to borrow them each time.

I've set a static IP address on the Pi by editing the cmdline.txt file. (The Pi is running the lastest version of Raspbian.)

ip=10.0.0.20

I've given the eth interface on my laptop a corresponding static IP address. (The laptop is running Ubuntu.)

ip ad add 10.0.0.10/24 dev eth0

I've connected the two together with an ethernet cable and can successfully ping the Pi from my laptop.

What I can't do is ssh to the Pi. I'm getting a Connection refused response:

richard@richard-ThinkPad-X220:~$ ssh -vvv pi@10.0.0.20
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 10.0.0.20 [10.0.0.20] port 22.
debug1: connect to address 10.0.0.20 port 22: Connection refused
ssh: connect to host 10.0.0.20 port 22: Connection refused

One thing that this would imply is that sshd is not yet running on the Pi.

The official docs state that sshd runs by default, but is it possible that during an initial boot that other things (e.g. prompts waiting for user input) might block the boot at a certain level, meaning we don't reach the point at which sshd is started?

Where do I go from here? (Not "to the shops to buy a monitor"... )

Is what I'm trying actually possible?

Edit:

I've now tried the methods mentioned in the answers to the following post, but without success: Enabling SSH on RPi without screen - keystrokes for raspi-config?

Specifically, ensuring that the SSH init script is run at runlevel 2 still didn't allow me to connect.

Richard Horrocks
  • 373
  • 1
  • 3
  • 10

5 Answers5

11

For those of you running into this with the newer Raspbian images: there is a sshwitch systemd target, that checks for /boot/ssh, and if that file is present, it regenerates the SSH host keys and enables the SSH server.

So, to enable SSH, just add a file called ssh in the root of the boot partition (the FAT one, with the bootcode.bin file), and boot your Pi!

Edit: this worked on my 2017-01-11-raspbian-jessie-lite image.

tlhIngan
  • 3,372
  • 5
  • 21
  • 33
Steffan Karger
  • 211
  • 2
  • 2
5

The official docs state that sshd runs by default

On the latest image I have, 2015-11-21-raspbian-jessie-lite.img, this is not true. Debian/Raspbian jessie currently uses systemd for init, but there is a sort of hybrid backward-SysV-compatible mechanism built in, and I notice on the running system I created from this image (using a screen and keyboard for the initial setup), where sshd is now enabled, there's a trigger in both the systemd and the old SysV rc.d directories. Presumably this is how the backward-compatible mechanism works (I enabled ssh via systemd). In any case, there's only one sshd instance with a PPID of 1 running.

For the working system, there is an entry in /etc/rc[2,3,4,5].d for S02ssh (the exact priority number, 02, is set when the service is enabled and may vary). There is also a /etc/systemd/system/multi-user.target.wants/ssh.service.

In the base image, however...

...There is no entry in /etc/systemd and there is a K01ssh for runlevels 2, 3, 4, 5. That will pretty much guarantee no sshd is running.

My suggestion is to first try setting just the SysV entry. From the etc directory of the second partition on the SD card:

for i in 2 3 4 5; do \
ln -s ../init.d/ssh rc$i.d/S02ssh; \
rm rc$i.d/K01ssh \
done

Check to make sure the links are there and they point to the right place with stat. I believe this should be sufficient and you can now try booting the system. If so, after you get in remove those links and run systemctl enable ssh, then check the links have been recreated (remember, the priority may be different).

If you still get "Connection refused", create a link from [SD_rootfs]/lib/systemd/system/ssh.service to [SD_rootfs]/etc/systemd/default.target.wants/ssh.service and try again.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
1

Sorry about this being an answer but not enoght credit to just comment.

Is ssh service up? If it is possible, and it is one of the raspberry installation images, try raspi-config just to enable ssh.

Another way, check with if ssh is loaded and enabled

sudo service --status-all|grep ssh

Maybe the ssh port 22 rejects connection because the service is not ready

goldilocks
  • 60,325
  • 17
  • 117
  • 234
Jesus Cepeda
  • 399
  • 1
  • 9
1

https://www.raspberrypi.org/blog/a-security-update-for-raspbian-pixel/ This link for Rasbian PIXEL version operation system.

George
  • 21
  • 1
0

The version of Jessie lite dated 26 Feb 2016 has ssh enabled by default.