pavelsr
Posts: 1
Joined: Fri Oct 27, 2017 9:51 am

Problem with enabling ssh without monitor

Fri Oct 27, 2017 10:07 am

Hi makers,

I have a problem with headless setup of my raspberry pi 3 with latest Raspbian Stretch Lite (2017-09-07-raspbian-stretch-lite.img).

As we know, SSH was disabled by default in Raspbian versions released after November 2016, and according official blog post
If you want to enable SSH, all you need to do is to put a file called ssh in the /boot/ directory. The contents of the file don’t matter: it can contain any text you like, or even nothing at all. When the Pi boots, it looks for this file; if it finds it, it enables SSH and then deletes the file.
Ok, I made

Code: Select all

sudo touch ssh
inside /boot, nothing changed, when I tried to connect I have

Code: Select all

ssh [email protected]
ssh: connect to host 192.168.0.106 port 22: Connection refused
From another forum post I read that I need to put the file not in /boot/ directory, but in boot partition of SD card. Ok, I did it and ssh file was deleted after boot. I checked boot log with monitor and looks like that Raspbian really saw ssh file:

Image

But I still can't connect via ssh, have port 22: Connection refused error

What can I do to fix the problem ?

User avatar
B.Goode
Posts: 9357
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Problem with enabling ssh without monitor

Fri Oct 27, 2017 5:18 pm

What can I do to fix the problem ?
If you are able to access the RPi via a conventional keyboard and display desktop interface it is easy to troubleshoot:

First check that the ssh listener/daemon really is configured:

Code: Select all

netstat -tnlp
Look for a tcp (not tcp6) entry for :22

Then check the actual IP address of your RPi:

Code: Select all

ip addr
Or
ifconfig eth0
If the sshd service is running and you specify the correct target address all should be ok, unless there is some external block in place, maybe in your home router?

drgeoff
Posts: 10245
Joined: Wed Jan 25, 2012 6:39 pm

Re: Problem with enabling ssh without monitor

Fri Oct 27, 2017 6:08 pm

Out of the dozens of home routers I have examined not a single one had the capability to block ports of the software kind (22, 23, 80 etc) in traffic between its hardware LAN ports.

RonR
Posts: 794
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Problem with enabling ssh without monitor

Fri Oct 27, 2017 7:56 pm

pavelsr wrote:
Fri Oct 27, 2017 10:07 am
But I still can't connect via ssh, have port 22: Connection refused error

What can I do to fix the problem ?
After adding an empty ssh file in /boot, verify that your /boot directory has the following files (ignore file sizes and timestamps):

Code: Select all

-rwxr-xr-x 1 root root   15830 Oct 25 17:07 bcm2708-rpi-0-w.dtb
-rwxr-xr-x 1 root root   15367 Oct 25 17:07 bcm2708-rpi-b.dtb
-rwxr-xr-x 1 root root   15626 Oct 25 17:07 bcm2708-rpi-b-plus.dtb
-rwxr-xr-x 1 root root   15086 Oct 25 17:07 bcm2708-rpi-cm.dtb
-rwxr-xr-x 1 root root   16693 Oct 25 17:07 bcm2709-rpi-2-b.dtb
-rwxr-xr-x 1 root root   17794 Oct 25 17:07 bcm2710-rpi-3-b.dtb
-rwxr-xr-x 1 root root   16550 Oct 25 17:07 bcm2710-rpi-cm3.dtb
-rwxr-xr-x 1 root root   50248 Oct 25 17:07 bootcode.bin
-rwxr-xr-x 1 root root     160 Oct 25 17:02 cmdline.txt
-rwxr-xr-x 1 root root    1615 Oct 25 17:08 config.txt
-rwxr-xr-x 1 root root   18693 Aug 21  2015 COPYING.linux
-rwxr-xr-x 1 root root    2578 Oct 25 17:07 fixup_cd.dat
-rwxr-xr-x 1 root root    6551 Oct 25 17:07 fixup.dat
-rwxr-xr-x 1 root root    9694 Oct 25 17:07 fixup_db.dat
-rwxr-xr-x 1 root root    9694 Oct 25 17:07 fixup_x.dat
-rwxr-xr-x 1 root root     145 Sep  7 10:54 issue.txt
-rwxr-xr-x 1 root root 4579640 Oct 25 17:07 kernel7.img
-rwxr-xr-x 1 root root 4380200 Oct 25 17:07 kernel.img
-rwxr-xr-x 1 root root    1494 Nov 18  2015 LICENCE.broadcom
-rwxr-xr-x 1 root root   18974 Sep  7 10:54 LICENSE.oracle
drwxr-xr-x 2 root root   10240 Sep  7 09:58 overlays
-rwxr-xr-x 1 root root       0 Oct 27 14:35 ssh   <--- THIS IS THE ADDED SSH FILE
-rwxr-xr-x 1 root root  667460 Oct 25 17:07 start_cd.elf
-rwxr-xr-x 1 root root 4956676 Oct 25 17:07 start_db.elf
-rwxr-xr-x 1 root root 2820196 Oct 25 17:07 start.elf
-rwxr-xr-x 1 root root 3904228 Oct 25 17:07 start_x.elf
You should now be able to insert the SD card in your Pi and connect via SSH. Be patient as Raspbian will first resize its root partition and reboot before you will be able to connect via SSH. If you still get connection refused, take another look at the /boot and verify that the empty ssh file is now gone (Raspbian deletes it after enabling SSH). If the empty ssh file is gone but you're still getting connection refused, your problem is probably elsewhere (such as using the wrong ip address).

User avatar
HawaiianPi
Posts: 5209
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Problem with enabling ssh without monitor

Sat Oct 28, 2017 10:20 am

Have you reimaged the SD card after your failed attempt? If not, start over with a freshly imaged SD card. Because turning off the power without a clean shutdown can affect SSH key generation and disable SSH connections.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

duckor
Posts: 17
Joined: Sat Oct 14, 2017 1:31 am

Re: Problem with enabling ssh without monitor

Tue Oct 31, 2017 8:34 pm

I'm beginning to think it's a bug with Stretch.

From what I'm seeing:

Put file "ssh" on the boot partition.

On first boot Raspbian resizes the partitions.

SSH is enabled for this session.

After resize Raspbian reboots.

No more due to file being deleted.

?????

User avatar
B.Goode
Posts: 9357
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Problem with enabling ssh without monitor

Tue Oct 31, 2017 8:40 pm

No more due to file being deleted.
If you mean the ssh marker file is no longer in the 'boot' section of the microSD card, that is expected and documented behaviour.

See https://www.raspberrypi.org/documentati ... /README.md in Section 3.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5348
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Problem with enabling ssh without monitor

Tue Oct 31, 2017 8:48 pm

B.Goode wrote:
No more due to file being deleted.
If you mean the ssh marker file is no longer in the 'boot' section of the microSD card, that is expected and documented behaviour.
See https://www.raspberrypi.org/documentati ... /README.md in Section 3.
+1
Before re-booting, did you change the default password (for pi) to something else?
IIRC, I think that's needed too. I'm lucky enough (or have too many Pi's that need such) to "always" have access to a keyboard & display so haven't (yet) tried the "dummy ssh file" approach but since ssh has been disabled by default have done both, usually with Raspbian "Full" but also with a recent, quick test of "Lite":
viewtopic.php?f=66&t=195378&p=1222714#p1222714
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, A+ and a B2) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

DirkS
Posts: 10143
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Problem with enabling ssh without monitor

Tue Oct 31, 2017 9:06 pm

FTrevorGowen wrote:
Tue Oct 31, 2017 8:48 pm
Before re-booting, did you change the default password (for pi) to something else?
IIRC, I think that's needed too.
Not necessary, but you'll get warning messages if you don't

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5348
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Problem with enabling ssh without monitor

Tue Oct 31, 2017 9:20 pm

DirkS wrote:
FTrevorGowen wrote:
Tue Oct 31, 2017 8:48 pm
Before re-booting, did you change the default password (for pi) to something else?
IIRC, I think that's needed too.
Not necessary, but you'll get warning messages if you don't
Thanks for clarifying (I didn't RC then ;) ) Since I always change the password (and, usually, the hostname too) if a Pi is going to be networked** I've never seen the warnings and had got the impression that, at some point (eg. "three strikes and you're out) ssh was disabled again.
Trev.
** ie. may not have done so here: http://www.cpmspectrepi.uk/raspberry_pi ... Powered.22
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, A+ and a B2) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
HawaiianPi
Posts: 5209
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Problem with enabling ssh without monitor

Wed Nov 01, 2017 7:43 am

duckor wrote:
Tue Oct 31, 2017 8:34 pm
I'm beginning to think it's a bug with Stretch.?
There's no bug. It works as intended. This is the procedure I use to set up my Pi Zero with a Raspbian compatible USB WiFi dongle (or a model B or Pi2B with the same dongle). It also works for my Pi3 with the built-in WiFi. It works with Raspbian Jessie and Stretch, Desktop or Lite.
  1. Grab the latest Raspbian image from https://www.raspberrypi.org/downloads/raspbian/
  2. Grab the Etcher software from https://etcher.io/
  3. Install Etcher and use it to write the Raspbian image to your SD card. You don't need to extract the image or format the card prior to writing. Just choose the Raspbian .zip, pick your SD card and write (if you have trouble, verify the SHA256 checksum of the download).
  4. Remove and reinsert the SD card so that your Windows or Mac PC can see the small FAT32 partition on the SD card.
  5. On that small partition, create a file with the name ssh or ssh.txt (if you want SSH access, otherwise skip this step).
  6. To connect to a wireless network, create a file on the partition called wpa_supplicant.conf which has the following inside.

    Code: Select all

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=US
    
    network={
    	ssid="Your network SSID"
    	psk="Your WPA/WPA2 security key"
    	key_mgmt=WPA-PSK
    }
  7. Edit country=, ssid= and psk= with your information and save the file.
  8. Safely eject the card from your PC and use it to boot the Pi.
If Raspbian finds an ssh file it will enable SSH and delete the file, and when it finds a wpa_supplicant.conf file, it will move it to its correct location and connect to your wireless network. After giving it enough time to boot I check the list of clients connected to my router to find the IP, and I am able to SSH into the Pi. You could also try SSH into [email protected] (or raspberrypi.local).

If this doesn't work for you, then either:
1. You did something wrong (make sure you edit wpa_supplicant.conf with a pure text editor, not a word processor).
2. There is something funky going on with your network (check your router for things like MAC address filtering or wireless client/AP isolation).
3. Something is broken (highly unlikely, but not impossible).

I think that everyone playing with a Raspberry Pi computer should have a serial console cable. It's a great tool for troubleshooting because you can monitor the boot output messages to see any errors and then login to troubleshoot, and it does not require a network connection. They're not expensive either. I use a CP2102 USB TTL (3V3) adapter, which you can get from ebay for less than $2 (or $5-$10 from Amazon).

Here it is connected to my Pi Zero and plugged into an old Netbook.
Image

And the serial terminal output on the Netbook it's connected to.
Image
As you can see, I am logged into the CLI of the OS on the Pi Zero.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

fivdi
Posts: 208
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Problem with enabling ssh without monitor

Wed Nov 01, 2017 8:57 am

@HawaiianPi Nice job, that's an excellent post.

jahboater
Posts: 5074
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Problem with enabling ssh without monitor

Wed Nov 01, 2017 9:19 am

+1 very useful.

Please could you give a link to where you purchased the cable from?

User avatar
HawaiianPi
Posts: 5209
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Problem with enabling ssh without monitor

Wed Nov 01, 2017 10:23 am

jahboater wrote:
Wed Nov 01, 2017 9:19 am
+1 very useful.

Please could you give a link to where you purchased the cable from?
I purchased mine many years ago for Arduino projects, so I doubt any ebay links from then would still be valid. Just go to ebay and search for CP2102. There are zillions of them, and prices are all over the place. As long as it's a CP2102 chip based model it should work the same as any other. Typically they run in the $2-$5 range, but there are a few for under $2, and even some under $1.50.

There are 5 and 6 pin models. The 5 pin models are mostly missing the DTR line, which is important for Arduino but not needed for the Pi serial console (Pi only needs RXD, TXD and GND, which they all have). So if you don't care about Arduino compatibility, get either type. The ones I have are all 6 pin, but even some of those don't have DTR, so it's a little whacky because they all aren't wired the same. Generally if you purchase a bunch at once from one vendor they will all be the same (for that order). And usually the pictures show what you are getting. I purchased mine in several different batches, which is why I have several different ones.

As long as you follow the labels on the output pins you'll be okay. The connections from the USB TTL adapter to the Pi are:

GND (ground) > GPIO pin 06 (GND)
RXD > GPIO pin 08 (TXD)
TXD > GPIO pin 10 (RXD)

Note that in my picture the Pi Zero has four connections, and no micro-USB power cord. The CP2102 also has 3V3 and 5V outputs, so for the Zero I connected the 5V to GPIO pin 02 (5V) to provide power. It would probably be okay for a model A or B as well (although it would bypass the power protection), but a Pi2 or Pi3 should have its own power supply and only the 3 connections listed above.

For a serial terminal under Linux I install screen and open the serial terminal with sudo screen /dev/ttyUSB0 115200. Under Windows you can use PuTTY with Serial as the connection type, the COM port number under Serial line, and 115200 as the speed (check the port number in Device Manager). With Windows 10 you can also use the Windows Subsystem for Linux (WSL), but you'll need the Fall Creators Update to use serial ports. The procedure is similar to Linux, but the COM port will be ttyS# (note the capital S), with # being the port number Windows 10 assigned to your adapter (if Device Manager shows COM4, you'll use sudo screen /dev/ttyS4 115200 to open the serial terminal). WSL is still beta, so PuTTY might be a little more reliable, but I have found that hitting enter a few times will often connect when the terminal window isn't showing any output.

Linux supports the CP2102 directly. Windows will need a driver: CP210x_Windows_Drivers.zip (not sure about Mac).

EDIT:
This one looks interesting, because it has a micro-USB jack instead of a USB-A plug (so you'd connect it with a micro-USB cable). Even though I have a pile of the other ones left over, I couldn't resist ordering a few of these. LOL! I really should learn to resist, because I have spent the last week trying to thin out the fluff in my stuff in preparation to moving in the next month or two. And now I just ordered more stuff I don't really need. I just can't resist cute little electronic doodads, especially when they're so cheap! And now begins the long wait for China shipping (I hope it gets here before we move :? ...)
Last edited by HawaiianPi on Wed Nov 01, 2017 10:46 am, edited 1 time in total.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

jahboater
Posts: 5074
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Problem with enabling ssh without monitor

Wed Nov 01, 2017 10:46 am

Thats an extremely useful post, thanks.

duckor
Posts: 17
Joined: Sat Oct 14, 2017 1:31 am

Re: Problem with enabling ssh without monitor

Sun Nov 05, 2017 3:08 pm

B.Goode wrote:
Tue Oct 31, 2017 8:40 pm
No more due to file being deleted.
If you mean the ssh marker file is no longer in the 'boot' section of the microSD card, that is expected and documented behaviour.

See https://www.raspberrypi.org/documentati ... /README.md in Section 3.
I don't think you quite understand what I'm talking about.


Steps:

Burn Raspbian Lite to SD.
Add the SSH file.
Pop the card in the Pi and boot.
On the FIRST BOOT ON A FRESH IMAGE Raspbian will resize to fit the whole card and then RESTART.
THIS IS THE FIRST BOOT, SSH IS DELETED ON FIRST BOOT
Pi then reboots but SSH is no longer available due to it not being the first boot.



EDIT::

I just tried again, and it worked. I'll do some more testing to see if I can get it to reproduce.

User avatar
davidcoton
Posts: 4546
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Problem with enabling ssh without monitor

Sun Nov 05, 2017 5:12 pm

duckor wrote:
Sun Nov 05, 2017 3:08 pm
On the FIRST BOOT ON A FRESH IMAGE Raspbian will resize to fit the whole card and then RESTART.
THIS IS THE FIRST BOOT, SSH IS DELETED ON FIRST BOOT
Pi then reboots but SSH is no longer available due to it not being the first boot.

EDIT::

I just tried again, and it worked. I'll do some more testing to see if I can get it to reproduce.
Yes, ssh file in /boot is deleted on first boot, but after ssh has been enabled by the appropriate settings in the main (root) partition. So ssh is enabled on every subsequent reboot, until you do something to disable it.
If you saw something different, then we will probably never know why. :o :shock: :? :roll:
Signature retired

User avatar
HawaiianPi
Posts: 5209
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Problem with enabling ssh without monitor

Sun Nov 05, 2017 7:26 pm

Yup, once SSH is enabled it's on until you turn it off. Wouldn't make much sense to have to enable it on every boot.
davidcoton wrote:
Sun Nov 05, 2017 5:12 pm
If you saw something different, then we will probably never know why. :o :shock: :? :roll:
My guess would be that the OP pulled the power when SSH didn't work and messed up key generation, so SSH didn't work after that, until the card was re-imaged (which was my first reply to this thread).
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

duckor
Posts: 17
Joined: Sat Oct 14, 2017 1:31 am

Re: Problem with enabling ssh without monitor

Mon Nov 06, 2017 7:09 pm

HawaiianPi wrote:
Sun Nov 05, 2017 7:26 pm
Yup, once SSH is enabled it's on until you turn it off. Wouldn't make much sense to have to enable it on every boot.
davidcoton wrote:
Sun Nov 05, 2017 5:12 pm
If you saw something different, then we will probably never know why. :o :shock: :? :roll:
My guess would be that the OP pulled the power when SSH didn't work and messed up key generation, so SSH didn't work after that, until the card was re-imaged (which was my first reply to this thread).
Nope. I'll be doing more testing today to see if I can reproduce.

jahboater
Posts: 5074
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Problem with enabling ssh without monitor

Wed Nov 08, 2017 2:29 pm

HawaiianPi wrote:
Wed Nov 01, 2017 10:23 am
EDIT:
This one looks interesting, because it has a micro-USB jack instead of a USB-A plug (so you'd connect it with a micro-USB cable).
I ended up using this one:-

https://www.adafruit.com/product/954

I just enabled the serial port in raspi-config / interfaces, and used screen on the Linux PC.
Works well!

User avatar
HawaiianPi
Posts: 5209
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Problem with enabling ssh without monitor

Thu Nov 09, 2017 5:51 am

jahboater wrote:
Wed Nov 08, 2017 2:29 pm
I ended up using this one:-

https://www.adafruit.com/product/954

I just enabled the serial port in raspi-config / interfaces, and used screen on the Linux PC.
Works well!
Yup, the Adafruit one is nice. Better support (Adafruit is awesome), better package (no bare PCB), and you'll certainly receive it faster than economy shipping from China, but it does cost nearly 8X more (+ shipping) and no DTR line (only important if you also want to use it with Arduino). Although I see the cheap one on ebay now has a shipping charge as well (it was $1.25 with free shipping when I ordered). And, of course, I'm still waiting for it...
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

adrennes
Posts: 2
Joined: Thu Apr 12, 2018 9:23 pm

Re: Problem with enabling ssh without monitor

Thu Apr 12, 2018 9:31 pm

With Raspbian Stretch Lite as well as Raspbian Stretch, I have the same problem: SSH connection disappears.
I tried to ping the Raspberry, with success. This is not an IP address issue.
sudo [email protected] gets connection refused.

I tried this with success:
sudo ssh [email protected]
and then SSH works.

Strange, but works. Do some other users confirm ? Anyone knows why it works ?

User avatar
HawaiianPi
Posts: 5209
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Problem with enabling ssh without monitor

Sun Apr 29, 2018 11:17 pm

If you have to use sudo with ssh, then you have probably messed up permissions in your OS (by using sudo inappropriately previously).
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

Return to “Troubleshooting”