10

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.

  • Assuming you are pinging the Pi and it is running a recent Raspbian then it should work. The only alternative I can suggest is to login via the UART on pins 8 and 10. That does require wires and a 3V3 compatible USB serial dongle. – joan Jan 30 '16 at 10:18
  • Setting static addresses only complicates the issue. If you didn't fiddle with it you should be able to connect with ssh pi@raspberrypi.local You don't seem to think telling us how you actually try to ssh is important. – Milliways Jan 30 '16 at 12:29
  • I've tried removing the static IP address from the Pi's config, and attempted ping pi@raspberrypi.local. But this doesn't work because raspberrypi.local is an unknown host. Wouldn't it need an entry in /etc/hosts on my laptop to be able to resolve it? – Richard Horrocks Jan 30 '16 at 13:23
  • Let me know what further details about how I'm SSHing to supply, and I'll gladly provide them - apologies if anything's missing. Thanks for the suggestions so far :) – Richard Horrocks Jan 30 '16 at 13:28
  • 1
    You can run sudo nmap 10.0.0.20 on the laptop. If it shows port 22 is open then SSH is running, otherwise it's not running. It won't fix it, but it'll tell you what's happening. – garethTheRed Jan 30 '16 at 16:41
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.

  • Thanks for the very detailed instructions. I'd noticed K01ssh in the rc2.d directory and renamed it, but hadn't spotted the others in the other rc directories. Removing those using your script didn't help, unfortunately. (I checked they were created, as you suggested.) For the second method, I don't have an ssh.service entry in the etc/systemd/system/multi-user.target.wants/ directory, and the lib/systemd/system/ directory isn't accessible. The system can't even tell it's a directory (and running file gives me: ERROR: cannot open lib/systemd/system' (Input/output error)`). – Richard Horrocks Jan 30 '16 at 15:51
  • Note that I'm not using the Lite image, but the full-fat image of the same date as you. – Richard Horrocks Jan 30 '16 at 15:52
  • Have a look at the init directories mentioned above on the card. You should be able to tell whether ssh is enabled or not. If it is, correct IP + ssh running != "Connection refused", so something has gone wrong somewhere and you will have to find a screen and keyboard to diagnose it. Alternately (or as well), you could use something like wireshark to see what packets are going back and forth; this would prove definitely what is happening on the network. – goldilocks Jan 30 '16 at 16:17
  • Okay, had a poke around with Wireshark but didn't get anywhere. Then decided to burn a Lite image and try that. I noticed that the systemd files you mentioned were present, so attempted your second suggestion, which worked :) Unsure why things were different between the images, but it could have been my hacking around that affected something in first image. (I've no idea what... ) Thanks very much for your help. – Richard Horrocks Jan 30 '16 at 17:48
  • For the sake of completeness, I tried again with a fresh full-fat Jessie image burnt to a different SD card, but again, the lib/systemd/system/ directory was inaccessible. The same goes for a Wheezy image. Only the Lite image allowed me to access the directory and therefore complete the instructions. – Richard Horrocks Jan 31 '16 at 11:10
10

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.

  • This works well. If you have a keyboard handy, type: pi<enter> raspberry<enter> sudo touch /boot/ssh<enter> sudo reboot<enter> then watch your router as the device gets an ip, then ssh pi@<thatip> and you will feel like a hacker. – nurettin Jan 28 '18 at 18:09
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

  • 1
    On current versions of raspbian you'd probably want to use systemctl --list-units | grep ssh (or better yet the more informative systemctl status ssh). But you are essentially correct, "Connection refused" means nothing is listening on the port. If ssh is running, then the IP is wrong. – goldilocks Jan 30 '16 at 13:09
  • 2
    Thanks for the answer. The problem with your suggestion is that I have no way of running the command, because I can't access the Pi to run it. Chicken and egg. :( I know the IP address is correct because I can ping it (and I know nothing else on the network has the same address). – Richard Horrocks Jan 30 '16 at 13:18
1

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

  • This really doesn't seem to answer the question in any way. – Jacobm001 Feb 17 '17 at 22:57
  • Although the useful information is only in the link (rather than in the answer response, which is where it should be), this is at least official raspberrypi.org documentation, and the section "What has changed?" in the linked page detailes the security issues that caused the required changes (ie disabling ssh by default), and details the /boot/sshfix. – Roberto Tyley Mar 6 '17 at 15:00
0

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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