0

Background: I setup my wireless without a screen by mounting my distribution image(2018-04-18-raspbian-stretch-lite.img) according to the instructions on these links.

mounting distribution image

changing files to connect to wireless

and then using the linux dd command to put the modified image on my SD card

with Arch linux I use $ip addr to view my public ip address and $sudo nmap -sn XXX.XXX.X.XXX/XX to view connected devices on my wireless network. The raspberry pi shows up with its ip address and I have included the ssh file in the boot folder of the raspberry pi to enable ssh, but when I try to ssh into it using $ssh [email protected] I get ssh: connect to host XXX.XXX.X.XXX port 22: Connection refused. I believe the problem in this latest distribution is that placing ssh into boot doesn't enable ssh anymore. A commenter called Decades references that it does not work for him either in a recent post located here. What is an alternative to placing a file named ssh into the raspberry pi boot directory that would work for enabling ssh on boot?

Note: XXX.XXX.X.XXX/XX or XXX.XXX.X.XXX represents an ip address.

edit: the issue was that I placed ssh in the boot directory not the boot partition. ssh now works fine.

9
  • Please edit your question and copy the contents of your wpa_supplicant.conf to it and also give us the output from ssh -vv pi@>ip addr<
    – Ingo
    Commented May 18, 2018 at 23:36
  • Add country=GB (replace it with your country code) into your wpa_supplicant.conf on SD card in addition to the network SSID and password setup. You don't necessary to log in using IP address, if everything working, you can just log in using ssh [email protected].
    – hcheung
    Commented May 19, 2018 at 2:38
  • @Ingo the contents of wpa_supplicant aren't relevant to the question. I am able to connect the raspberry pi to wifi but am having trouble with ssh. I already have given you the output of my attempted ssh connection. The computer was able to contact the device, but because ssh is disabled on boot it refused the connection.
    – A.B.
    Commented May 19, 2018 at 3:00
  • I believe the problem in this latest distribution is that placing ssh into boot doesn't enable ssh anymore - the thing is /boot/ssh is removed on boot - however, ssh is enabled - if there's a reboot, and you do not configure ssh to be enabled, the next boot results in ssh being not available. One thing a pi does on first boot is extend the root partition ... and then reboot - so, perhaps you simply need to put /boot/ssh back on the sd card Commented May 19, 2018 at 3:06
  • I just realised a little confusion in the above. ssh is enabled by adding /boot/ssh - which you know - but it is temporary (until the next boot) unless you enable it "permanently" (using raspi-config is the easiest way) - and I'm fairly sure the first boot of a raspbian image results in at least one reboot Commented May 19, 2018 at 3:13

1 Answer 1

1

I have just tested with a fresh flashed Raspbian Stretch Lite 2018-04-18 on a Raspberry Pi 3B+. Adding an empty file /boot/ssh will persistent enable the ssh server on the Raspberry Pi. Even after several boots I get (have a serial tty-usb console cable):

pi@raspberrypi:~$ systemctl status ssh.service
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-04-18 01:08:39 UTC; 1 months 0 days ago
  Process: 524 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 527 (sshd)
   CGroup: /system.slice/ssh.service
           └─527 /usr/sbin/sshd -D

Apr 18 01:08:39 raspberrypi systemd[1]: Starting OpenBSD Secure Shell server...
Apr 18 01:08:39 raspberrypi sshd[527]: Server listening on 0.0.0.0 port 22.
Apr 18 01:08:39 raspberrypi sshd[527]: Server listening on :: port 22.
Apr 18 01:08:39 raspberrypi systemd[1]: Started OpenBSD Secure Shell server.
pi@raspberrypi:~$

To enable wifi you have to add /boot/wpa_supplicant.conf on your raspi with something like:

country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="[email protected]"
    psk="verySecretPassword"
}

You don't use a pi-3b+ but for the completeness for other readers: Adding the country=XX line is essential for Pi 3 B+ because without it wifi will not start. Look at release notes:

018-03-13: * Raspberry Pi 3 B+ support
* WiFi is disabled until wireless regulatory domain is set (Pi 3 B+ only) - The domain can be done through 'Raspberry Pi Configuration' (rc_gui), 'raspi-config' or by setting 'country=' to an appropriate ISO 3166 alpha2 country code in /etc/wpa_supplicant/wpa_supplicant.conf.
* Default wireless regulatory domain is now unset

Putting it all together I have done this:

pc ~$ # on a pc with debian and mounted SD card to /dev/sdb
pc ~$ sudo -Es
pc ~# unzip -p 2018-04-18-raspbian-stretch-lite.zip | dd of=/dev/sdb bs=4M conv=fsync
pc ~# mount /dev/sdb1 /mnt/
pc ~# touch /mnt/ssh
pc ~# cat >/mnt/wpa_supplicant.conf <<EOF   # use your settings
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="[email protected]"
    psk="verySecretPassword"
}
EOF

pc ~# umount /mnt/
pc ~# exit
pc ~$

Put the SD card into your raspi and boot. If you do exactly the same as above you should be able to ssh into your raspi through wifi. If not the raspi isn't the reason (or it's broken). Look at your environment. Or you have done wrong settings.

1
  • edit: the issue was that I placed the ssh file in the boot directory instead of the boot partition.
    – A.B.
    Commented May 19, 2018 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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