h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

SSH problems with Raspberry Pi Zero W

Fri May 18, 2018 2:49 am

Yesterday, I successfully SSH'ed into my RPI but today I can't seem to do it for some reason. I encounter a connection close at port 22. I reformatted my microSD card and reflashed raspbian lite onto it, tried methods online, which include adding the empty SSH file and adding the conf file to connect to my router. I can ping my pi, but an SSH attempt yields a Connection Reset by 192.168.1.5 port 22. A verbose SSH yields:

C:\Users\UserName>ssh -vvv [email protected]

OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4

debug3: Failed to open file:C:\\Users\\UserName/.ssh/config error:2

debug3: Failed to open file:C:\\ProgramData\\ssh/ssh_config error:2

debug2: resolving "192.168.1.5" port 22

debug2: ssh_connect_direct: needpriv 0

debug1: Connecting to 192.168.1.5 [192.168.1.5] port 22.

debug1: Connection established.

debug1: identity file C:\\Users\\UserName/.ssh/id_rsa type 0

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_rsa-cert error:2

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_rsa-cert.pub error:2

debug1: key_load_public: No such file or directory

debug1: identity file C:\\Users\\UserName/.ssh/id_rsa-cert type -1

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_dsa error:2

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_dsa.pub error:2

debug1: key_load_public: No such file or directory

debug1: identity file C:\\Users\\UserName/.ssh/id_dsa type -1

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_dsa-cert error:2

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_dsa-cert.pub error:2

debug1: key_load_public: No such file or directory

debug1: identity file C:\\Users\\UserName/.ssh/id_dsa-cert type -1

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_ecdsa error:2

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_ecdsa.pub error:2

debug1: key_load_public: No such file or directory

debug1: identity file C:\\Users\\UserName/.ssh/id_ecdsa type -1

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_ecdsa-cert error:2

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_ecdsa-cert.pub error:2

debug1: key_load_public: No such file or directory

debug1: identity file C:\\Users\\UserName/.ssh/id_ecdsa-cert type -1

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_ed25519 error:2

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_ed25519.pub error:2

debug1: key_load_public: No such file or directory

debug1: identity file C:\\Users\\UserName/.ssh/id_ed25519 type -1

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_ed25519-cert error:2

debug3: Failed to open file:C:\\Users\\UserName/.ssh/id_ed25519-cert.pub error:2

debug1: key_load_public: No such file or directory

debug1: identity file C:\\Users\\UserName/.ssh/id_ed25519-cert type -1

debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.6

debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Raspbian-10+deb9u3

debug1: match: OpenSSH_7.4p1 Raspbian-10+deb9u3 pat OpenSSH* compat 0x04000000

debug2: fd 3 setting O_NONBLOCK

debug1: Authenticating to 192.168.1.5:22 as 'pi'

debug3: hostkeys_foreach: reading file "C:\\Users\\UserName/.ssh/known_hosts"

debug3: record_hostkey: found key type ECDSA in file C:\\Users\\UserName/.ssh/known_hosts:1

debug3: load_hostkeys: loaded 1 keys from 192.168.1.5

debug3: Failed to open file:C:\\Users\\UserName/.ssh/known_hosts2 error:2

debug3: Failed to open file:C:\\ProgramData\\ssh/ssh_known_hosts error:2

debug3: Failed to open file:C:\\ProgramData\\ssh/ssh_known_hosts2 error:2

debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521

debug3: send packet: type 20

debug1: SSH2_MSG_KEXINIT sent

Connection closed by 192.168.1.5 port 22

Any tips on how to proceed? Thanks.

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

Re: SSH problems with Raspberry Pi Zero W

Fri May 18, 2018 9:28 am

The majority of those errors seem to be failures of whatever SSH software you are using with Windows. Since you re-flashed Raspbian you may need to clear keys and configurations from your previous SSH session.

You could try PuTTY or WSL for SSH.
Last edited by HawaiianPi on Fri May 18, 2018 9:30 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?

User avatar
DougieLawson
Posts: 33603
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: SSH problems with Raspberry Pi Zero W

Fri May 18, 2018 9:29 am

How do you know that 192.168.1.5 is the address for your RPi? I'd guess it could be the address of your laptop from the collection of failures you've seen.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

Re: SSH problems with Raspberry Pi Zero W

Fri May 18, 2018 1:23 pm

DougieLawson wrote:
Fri May 18, 2018 9:29 am
How do you know that 192.168.1.5 is the address for your RPi? I'd guess it could be the address of your laptop from the collection of failures you've seen.
I used Nmap and found that this address correlates to my pi.

h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

Re: SSH problems with Raspberry Pi Zero W

Fri May 18, 2018 1:24 pm

HawaiianPi wrote:
Fri May 18, 2018 9:28 am
The majority of those errors seem to be failures of whatever SSH software you are using with Windows. Since you re-flashed Raspbian you may need to clear keys and configurations from your previous SSH session.

You could try PuTTY or WSL for SSH.
I SSHed from the windows cmd with admin privileges. I saw a few posts regarding clearing old SSh keys, but I can't figure out how to do it myself unfortunately.

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

Re: SSH problems with Raspberry Pi Zero W

Sat May 19, 2018 11:32 pm

h2252947 wrote:
Fri May 18, 2018 1:24 pm
I SSHed from the windows cmd with admin privileges. I saw a few posts regarding clearing old SSh keys, but I can't figure out how to do it myself unfortunately.
Did you install any SSH software, or are you using the new SSH functionality added recently with the Windows 10 spring update?
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?

h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

Re: SSH problems with Raspberry Pi Zero W

Sat May 19, 2018 11:47 pm

HawaiianPi wrote:
Sat May 19, 2018 11:32 pm
h2252947 wrote:
Fri May 18, 2018 1:24 pm
I SSHed from the windows cmd with admin privileges. I saw a few posts regarding clearing old SSh keys, but I can't figure out how to do it myself unfortunately.
Did you install any SSH software, or are you using the new SSH functionality added recently with the Windows 10 spring update?
Yes, I'm using the Windows 10 openSSH from the cmd. I also tried to use PUTTY to access my pi but it doesn't work.

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

Re: SSH problems with Raspberry Pi Zero W

Sat May 19, 2018 11:59 pm

I *think* the OpenSSH keys are stored in your user folder in a folder named .ssh

C:\Users\yourusername\.ssh\known_hosts

If you delete the known_hosts file it should treat it as a new SSH session.

What happened when you tried PuTTY?
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?

h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

Re: SSH problems with Raspberry Pi Zero W

Sun May 20, 2018 12:51 am

HawaiianPi wrote:
Sat May 19, 2018 11:59 pm
I *think* the OpenSSH keys are stored in your user folder in a folder named .ssh

C:\Users\yourusername\.ssh\known_hosts

If you delete the known_hosts file it should treat it as a new SSH session.

What happened when you tried PuTTY?
I deleted the known_hosts file and retried SSHing, it still gives me connection reset on port 22. Putty gives a Network error: Software caused connection abort error. Side note: the IP for the pi changed from 192.168.1.3 to 192.168.1.2. Is there a way to assign the pi a static IP?

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

Re: SSH problems with Raspberry Pi Zero W

Sun May 20, 2018 8:13 am

h2252947 wrote:
Sun May 20, 2018 12:51 am
Side note: the IP for the pi changed from 192.168.1.3 to 192.168.1.2. Is there a way to assign the pi a static IP?
Best way to do that is to reserve the I.P. in your router's DHCP settings. You assign the I.P. by MAC address, so your Pi0W will always get the same I.P. (even after an OS reinstall).
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?

n67
Posts: 788
Joined: Mon Oct 30, 2017 4:55 pm

Re: SSH problems with Raspberry Pi Zero W

Sun May 20, 2018 9:46 am

Even better is to remove the requirement of static IP.

If things are setup correctly, you should be able to access the Pi as:

YourHostName.local

regardless of what its IP is.
"L'enfer, c'est les autres"

If a post offends you, just put that poster on your foes list, and be done with it (and with them).

To do otherwise, risks being banned.

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

Re: SSH problems with Raspberry Pi Zero W

Sun May 20, 2018 10:06 am

n67 wrote:
Sun May 20, 2018 9:46 am
Even better is to remove the requirement of static IP.

If things are setup correctly, you should be able to access the Pi as:

YourHostName.local

regardless of what its IP is.
True if you have a Zeroconf network service running (Apple's iTunes or Bonjour print service installs Zeroconf on Windows).

ssh [email protected]

Of course that also assumes all your Pi computers have unique hostnames (if you have more than one, and you haven't changed the default hostnames, then they're all raspberrypi).
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?

h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

Re: SSH problems with Raspberry Pi Zero W

Sun May 20, 2018 7:15 pm

But I still can't modify anything because I can't get SSH to work. I don't know what to do at this point.

User avatar
DougieLawson
Posts: 33603
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: SSH problems with Raspberry Pi Zero W

Sun May 20, 2018 7:42 pm

If you can logon to your RPi (using a keyboard, mouse and TV/monitor) then run these commands in an LXterminal window

sudo touch /boot/ssh
sudo reboot


Get this: http://www.advanced-ip-scanner.com
Use it to scan your LAN for the address of your Raspberry.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

n67
Posts: 788
Joined: Mon Oct 30, 2017 4:55 pm

Re: SSH problems with Raspberry Pi Zero W

Sun May 20, 2018 8:38 pm

If you can logon to your RPi (using a keyboard, mouse and TV/monitor) then ...
In that case, you don't need to mess around with any of this "headless stuff".

You can just run raspi-config to enable SSH.

And you can use "ip" or "ifconfig" to tell you what your IP address is. No need for Fing or NMAP or whatever...
"L'enfer, c'est les autres"

If a post offends you, just put that poster on your foes list, and be done with it (and with them).

To do otherwise, risks being banned.

h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

Re: SSH problems with Raspberry Pi Zero W

Sun May 20, 2018 11:53 pm

DougieLawson wrote:
Sun May 20, 2018 7:42 pm
If you can logon to your RPi (using a keyboard, mouse and TV/monitor) then run these commands in an LXterminal window

sudo touch /boot/ssh
sudo reboot


Get this: http://www.advanced-ip-scanner.com
Use it to scan your LAN for the address of your Raspberry.
I saw multiple posts online about this, but I only have a laptop and no monitor/wired keyboard. I remember reading about setting up VNC on a laptop and pi to see the pi gui on a laptop screen.

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

Re: SSH problems with Raspberry Pi Zero W

Mon May 21, 2018 12:42 am

Okay, let's start over from scratch.

This is the procedure I use for setting up headless boot with SSH and wireless network. It works with Raspbian Jessie or Stretch, Desktop or Lite, and with the built-in WiFi on the Pi3B(+) & Pi Zero W, or a Raspbian compatible USB WiFi dongle on other models. Everything is done before you boot, and can be done on a Windows or Mac computer which only has access to the small FAT32 "boot" partition of a Raspbian imaged SD card.
  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 run Etcher, choose the Raspbian .zip you downloaded, pick your SD card and write.
    • If you have trouble, verify the SHA256 checksum of the download.
    • Writing an image to your card will erase everything previously on it!
  4. Remove and reinsert the SD card so that your Windows or Mac PC can see the small FAT32 partition on the card (labelled "boot").
    • If you get a message telling you the card must be formatted, cancel it.
  5. On that small FAT32 partition, create a file with the name ssh (or ssh.txt). It can be empty, the contents don't matter.
  6. To connect to a wireless network, create another file on the card 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=GB
    
    network={
         ssid="Your network name/SSID"
         psk="Your WPA/WPA2 security key"
         key_mgmt=WPA-PSK
    }
    • Edit country=, ssid= and psk= with your information and save the file.
    • Use the 2 letter country abbreviation in CAPS (without this you will have no WiFi).
    • Use a pure text editor, not a word processor, to edit the wpa_supplicant.conf file.
  7. Make sure that both files are in the main directory of the small FAT32 partition, not in any folder.
  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. If it finds a wpa_supplicant.conf file, it will move it to its correct location and connect to your wireless network. Give your Pi some time to boot and connect to your network (the first boot always takes longer), then you should be able to SSH into the Pi and configure it how you like.

If you have a Zeroconf network service installed (Apple's iTunes or Bonjour install Zeroconf), you can SSH into [email protected] (provided you don't have any other Pi computers on your network with the same default hostname). Otherwise you must SSH into your Pi's IP address, which you can find by logging into your router and checking the list of connected clients, or using a network scanner app (like Fing for smartphones).

To login using SSH from Windows, you can use an app called PuTTY, which looks like this (click picture for download link).
Image

In the Host Name (or IP address) field, enter either, make sure SSH is selected (it should be by default) and click on Open.

If you have done everything correctly, a terminal window will open and you should see a password request. Although, if it's the first time you've connected to your Pi, you may have to answer "yes" to a security question, and then you'll get the password prompt. After login you'll get a warning about having SSH enabled with the default password, so type passwd[Enter] and enter a new password (twice). And now you can do whatever you need to configure your little Raspberry Pi computer.

Code: Select all

sudo raspi-config
Will bring up the Raspbian configuration utility. If you have more than one Raspberry Pi computer on your network it's a good idea to change the hostnames to something unique so that they can easily be identified. From this utility you can enable the VNC server and use a RealVNC Viewer application on your main PC to get remote desktop access to your Pi.

Note:
If you have attempted this and failed, then unplugged power to turn off your Pi, you should start over with a freshly imaged card. Improperly powering down the Pi can cause SSH key generation to fail, which will prevent SSH logins (even if everything else is correct).
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?

h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

Re: SSH problems with Raspberry Pi Zero W

Mon May 21, 2018 2:12 am

HawaiianPi wrote:
Mon May 21, 2018 12:42 am
Okay, let's start over from scratch.

This is the procedure I use for setting up headless boot with SSH and wireless network. It works with Raspbian Jessie or Stretch, Desktop or Lite, and with the built-in WiFi on the Pi3B(+) & Pi Zero W, or a Raspbian compatible USB WiFi dongle on other models. Everything is done before you boot, and can be done on a Windows or Mac computer which only has access to the small FAT32 "boot" partition of a Raspbian imaged SD card.
  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 run Etcher, choose the Raspbian .zip you downloaded, pick your SD card and write.
    • If you have trouble, verify the SHA256 checksum of the download.
    • Writing an image to your card will erase everything previously on it!
  4. Remove and reinsert the SD card so that your Windows or Mac PC can see the small FAT32 partition on the card (labelled "boot").
    • If you get a message telling you the card must be formatted, cancel it.
  5. On that small FAT32 partition, create a file with the name ssh (or ssh.txt). It can be empty, the contents don't matter.
  6. To connect to a wireless network, create another file on the card 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=GB
    
    network={
         ssid="Your network name/SSID"
         psk="Your WPA/WPA2 security key"
         key_mgmt=WPA-PSK
    }
    • Edit country=, ssid= and psk= with your information and save the file.
    • Use the 2 letter country abbreviation in CAPS (without this you will have no WiFi).
    • Use a pure text editor, not a word processor, to edit the wpa_supplicant.conf file.
  7. Make sure that both files are in the main directory of the small FAT32 partition, not in any folder.
  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. If it finds a wpa_supplicant.conf file, it will move it to its correct location and connect to your wireless network. Give your Pi some time to boot and connect to your network (the first boot always takes longer), then you should be able to SSH into the Pi and configure it how you like.

If you have a Zeroconf network service installed (Apple's iTunes or Bonjour install Zeroconf), you can SSH into [email protected] (provided you don't have any other Pi computers on your network with the same default hostname). Otherwise you must SSH into your Pi's IP address, which you can find by logging into your router and checking the list of connected clients, or using a network scanner app (like Fing for smartphones).

To login using SSH from Windows, you can use an app called PuTTY, which looks like this (click picture for download link).
Image

In the Host Name (or IP address) field, enter either, make sure SSH is selected (it should be by default) and click on Open.

If you have done everything correctly, a terminal window will open and you should see a password request. Although, if it's the first time you've connected to your Pi, you may have to answer "yes" to a security question, and then you'll get the password prompt. After login you'll get a warning about having SSH enabled with the default password, so type passwd[Enter] and enter a new password (twice). And now you can do whatever you need to configure your little Raspberry Pi computer.

Code: Select all

sudo raspi-config
Will bring up the Raspbian configuration utility. If you have more than one Raspberry Pi computer on your network it's a good idea to change the hostnames to something unique so that they can easily be identified. From this utility you can enable the VNC server and use a RealVNC Viewer application on your main PC to get remote desktop access to your Pi.

Note:
If you have attempted this and failed, then unplugged power to turn off your Pi, you should start over with a freshly imaged card. Improperly powering down the Pi can cause SSH key generation to fail, which will prevent SSH logins (even if everything else is correct).
Wow, thanks for writing every step! I learned a few crucial points, such as a SSH key generation failure when improperly powering off a pi. I'll keep a note of this and tinker with my rpi tomorrow. Thanks again!

h2252947
Posts: 9
Joined: Fri May 18, 2018 2:47 am

Re: SSH problems with Raspberry Pi Zero W

Mon May 21, 2018 8:13 pm

The Pi works now! A sincere thank you for relieving my frustration with my pi, since it's my first time using one. :D

Return to “Troubleshooting”

Who is online

Users browsing this forum: tekkenhead and 57 guests