1

Greetings to the community!

I am struggling establishing an ssh connection from laptop (Windows 10) to my pi connected to it through an Ethernet cable (raspberry pi 3 model B+).

The process I am following is the above one:

1) Flashing an image (more specifically, this one) to my SD card

2) Go to the /etc/network/interfaces file of the image and added the following lines of code

auto eth0
iface eth0 inet dhcp

so that my pi takes a dynamic ip from the dhcp.

3) Add the SD card in my pi, connect my pi through Ethernet cable into my laptop and boot (Network Sharing is enabled in Windows options)

4) Get the static IP(192.168.137.85) of my pi assigned to it and connect to it through SSH using Putty successfully

So far so good....

Unfortunately, if I reboot my pi (unplugged it or whatever - of course after I have previously ended the SSH connection) and I try again to establish an SSH connection with it, it fails.

The workaround currently is repeat the procedure above(flash again the image etc.), but this is not a real solution..

Any idea what could possibly be the reason for the failed ssh connection after the pi reboot? Thanks in advance

  • 2
    what is that pi image? raspbian? which version of raspbian? or is it something else? /etc/network/interfaces hasn't been used to configure network settings for some time – Jaromanda X May 21 at 12:48
  • It is a custom rasbian image. – Thanasis G May 21 at 14:13
  • As long as we don't know what's customized on your Raspbian we cannot help much because /etc/network/interface isn't used on an unmodified Raspbian image. Using it will disable default dhcpcd networking. – Ingo May 21 at 20:56
  • Do you get the same problem with RaspiOS 2020-05-28? – Dougie May 29 at 11:53
  • I have not tried Raspbian yet. – Thanasis G May 30 at 15:59
2

Anything that stops the connection process is a possible cause.

  • No physical Ethernet connection (bad cable, lose connector, switch off, etc.)

  • Not connecting to the actual IP of the Pi (static vs DHCP)

  • Pi is using an IP address already in use by another system on the same LAN

  • Pi is hung, crashed, or failed to boot

  • Windows firewall blocking ping (ICMP), ssh protocols (Pi firewalls usually off)

Successful ping from Windows to Pi means the above issues are not the problem. Additional things:

  • Pi sshd service is not enabled and running

  • Userid used for ssh login non-existent or locked on the pi

Adding another user interface, monitor/keyboard/mouse or serial cable is the easiest (and typical) way to debug these issues.

Another approach is capture debugging information when on Pi boot.

  1. Put the SD card into a Linux computer and mount the second partition (the Pi's ext4 root partition).
  2. Add lines to script /etc/rc.local to capture debugging information to a text file /var/log/netdebug.
  3. Unmount and remove the SD card.
  4. Insert the SD in the Pi and power on.
  5. After a reasonable period of time, connect to the Pi.
  6. If you can't login, power off, remove the SD card.
  7. Again mount the SD card in a Linux computer and look at the saved debug messages in netdebug.

This method is time-consuming, but doesn't require additional hardware (assuming a Linux system exists to write the SD card in the first place). Following are example dash script lines to add to /etc/rc.local.

# Capture networking information
echo "# date" >/var/log/netdebug
date >>/var/log/netdebug
# Show network interfaces, MAC, IP addresses, status.
echo "\n# ip addr show" >>/var/log/netdebug
ip addr show >>/var/log/netdebug
# Show running (listening) TCP network services.
echo "\n# netstat -lptn" >>/var/log/netdebug
netstat -lptn >>/var/log/netdebug
# Show status of sshd service.
echo "\n# systemctl status sshd.service" >>/var/log/netdebug
systemctl status sshd.service >>/var/log/netdebug
# Show that Ethernet is working.
# Replace 192.168.1.1 with known valid IP on Pi's LAN.
echo "\n# ping -c 3 192.168.1.1" >>/var/log/netdebug
ping -c 3 192.168.1.1 >>/var/log/netdebug
# Show that DNS can translate "google.com" to an IP addres
# and that the Internet is reachable.
echo "\n# ping -c 3 google.com" >>/var/log/netdebug
ping -c 3 google.com >>/var/log/netdebug
| improve this answer | |
  • Thank you very much for your detailed answer! – Thanasis G May 28 at 23:03
1

Very probably, the PI was allocated a different IP address upon reboot. Since you are using DHCP the address can change. Assuming the default name of your PI is raspberrypi and you have Mdns aka Zeroconf aka Bonjour running on your Windows machine, you may be able to use a local hostname instead of an IP address.

In case you have Itunes installed on your computer, I think it comes with Bonjour.

Try: ping raspberrypi.local.

Otherwise, if you turn on network discovery or use a port scanner, you should be able to locate the PI and determine its current IP address.

| improve this answer | |
  • I am using advanced IP scanner(advanced-ip-scanner.com) and the static ip of pi remains the same after boot. – Thanasis G May 21 at 15:40
  • Can you ping the PI ? When you try to SSH into it what kind of error message do you get ? – Anonymous May 21 at 16:00
  • No,i try to ping both raspberrypi.mshome.net and ip adress that ip scanner gives me and i get "Request timeout".In Putty i get "Network error:Connection timeout". – Thanasis G May 21 at 16:16
  • Is it possible for you to connect a keyboard and a screen to the PI to check a few things without SSH ? For example systemctl status sshd.service to verify that SSH is really running. Also check IP address on the PI direct + current routing rules. – Anonymous May 21 at 16:23
  • yes,this is my next move.Thank you very much fo your responses and time! – Thanasis G May 21 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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