Cornetto
Posts: 6
Joined: Mon Aug 27, 2012 9:18 pm

SSH Problem

Mon Aug 27, 2012 9:30 pm

Hi,

I'm currently running my Pi through a serial connection but I would like to use SSH instead but I'm having problems.

When I try to connect with SSH i get "Read from socket failed: Connection reset by peer" when connecting with cygwin ("ssh pi@192.168.1.140" / "ssh 192.168.1.140") or "Network error: Software caused connection abort" when trying with PuTTy.

Using "ssh -v 192.168.1.140" in Cygwin gives the following log:

$ ssh -v 192.168.1.140
OpenSSH_6.0p1, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to 192.168.1.140 [192.168.1.140] port 22.
debug1: Connection established.
debug1: identity file /home/test/.ssh/id_rsa type -1
debug1: identity file /home/test/.ssh/id_rsa-cert type -1
debug1: identity file /home/test/.ssh/id_dsa type -1
debug1: identity file /home/test/.ssh/id_dsa-cert type -1
debug1: identity file /home/test/.ssh/id_ecdsa type -1
debug1: identity file /home/test/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-2
debug1: match: OpenSSH_6.0p1 Debian-2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0
debug1: SSH2_MSG_KEXINIT sent
Read from socket failed: Connection reset by peer

I've tried SSH'ing locally (ssh 127.0.0.1) on the Pi, that gives the same result.


Additionally:

pi@raspberrypi:~$ sudo service ssh status
sshd is running.

Network connection is fine, I can also ping the Pi successfully from my main computer.

Any clue what my problem could be?

Thanks in advance!

User avatar
Mortimer
Posts: 801
Joined: Sun Jun 10, 2012 3:57 pm

Re: SSH Problem

Mon Aug 27, 2012 9:59 pm

You might need to clear the SSH key and generate a new one.

On the Mac I have to :

ssh-keygen -R {RPi-IP-Address}

To delete the keys.

I then run the normal SSH command to connect and it generates a new key pair automatically.

Cornetto
Posts: 6
Joined: Mon Aug 27, 2012 9:18 pm

Re: SSH Problem

Mon Aug 27, 2012 10:10 pm

I've tried generating a new SSH-key but I can't seem to remove the existing one (only replace).

Cygwin says:

$ ssh-keygen -R 192.168.1.140
ssh-keygen: /home/Anders/.ssh/known_hosts: No such file or directory

Can't seem to delete it from the Pi itself either.

User avatar
jojopi
Posts: 2978
Joined: Tue Oct 11, 2011 8:38 pm

Re: SSH Problem

Mon Aug 27, 2012 11:45 pm

If you are running debian or raspbian on the Pi, try:

Code: Select all

sudo rm /etc/ssh/ssh_host_* && sudo dpkg-reconfigure openssh-server
(The "keygen -R" on the client is only necessary if you had connected successfully in the past. It tells the client that the server's host keys have changed.)

Cornetto
Posts: 6
Joined: Mon Aug 27, 2012 9:18 pm

Re: SSH Problem

Tue Aug 28, 2012 8:11 am

Thanks Mortimer and jojopi,
running

Code: Select all

sudo rm /etc/ssh/ssh_host_* 
and then

Code: Select all

sudo dpkg-reconfigure openssh-server
solved the problem!

Anyone care to explain what was wrong? So that I learnt something rather than just fixing it :D

User avatar
jojopi
Posts: 2978
Joined: Tue Oct 11, 2011 8:38 pm

Re: SSH Problem

Tue Aug 28, 2012 8:42 am

Cornetto wrote:Anyone care to explain what was wrong? So that I learnt something rather than just fixing it :D
The host keys, /etc/ssh/ssh_host*, are used to identify the ssh server to the client, so that users can be sure it is the right server (or at least the same one as last time) before sending it their password. The error you were getting, just after SSH2_MSG_KEXINIT, is very symptomatic of the server not being able to send its host keys because the files are missing or corrupt.

I do not know how that happened, though. The foundation's raspbian images normally create the host keys on the first boot and then never change them. If you are using one of those images, "cat /var/log/regen_ssh_keys.log" may tell you if any errors were logged during that process.

User avatar
Mortimer
Posts: 801
Joined: Sun Jun 10, 2012 3:57 pm

Re: SSH Problem

Tue Aug 28, 2012 9:23 am

I don't think I helped that much, but thanks for the recognition anyway. :P

Cornetto
Posts: 6
Joined: Mon Aug 27, 2012 9:18 pm

Re: SSH Problem

Tue Aug 28, 2012 10:43 am

So the key wasn't a problem, but the files containing them? Therefor simply generating new keys with "ssh-keygen" didn't solve the problem?

Thanks again guys!

DanR
Posts: 7
Joined: Fri Jan 18, 2013 1:20 pm

Re: SSH Problem

Sat Feb 09, 2013 1:03 am

Awesome, this fixed my issue which was driving me insane. Many Thanks!!

User avatar
rew
Posts: 408
Joined: Fri Aug 26, 2011 3:25 pm

Re: SSH Problem

Sat Feb 09, 2013 5:58 pm

Cornetto wrote:So the key wasn't a problem, but the files containing them? Therefor simply generating new keys with "ssh-keygen" didn't solve the problem?
It was the host keys that formed the problem. I know ssh-keygen to generate user-keys by default. It's probably also the one generating host keys, but it would need a bunch of options. I don't know them. so, just deleting the keys and having a reboot solve the problem or the dpkg-reconfigure, is saves us some searching at what options to give ssh-keygen.
Check out our raspberry pi addons: http://www.bitwizard.nl/shop/

embeddedprogrammer
Posts: 2
Joined: Tue Dec 20, 2016 12:10 am

Re: SSH Problem

Tue Dec 20, 2016 12:12 am

I had the same problem with the latest version of raspian (pixel). Thanks a lot for posting this. I just wish I had seen it before debugging network, firewall, windows 10, etc for the last four hours.

embeddedprogrammer
Posts: 2
Joined: Tue Dec 20, 2016 12:10 am

Re: SSH Problem

Tue Dec 20, 2016 9:29 am

embeddedprogrammer wrote:I had the same problem with the latest version of raspian (pixel). Thanks a lot for posting this. I just wish I had seen it before debugging network, firewall, windows 10, etc for the last four hours.

Actually I think I figured out what caused the problem. I had a PI B+ which overheated and died, and I took the microSD out of that, put it in an SD adapter, and used that for an older PI model B which I had with me for a backup. Evidently you cannot move a Raspian boot image from one PI to another without regenerating these ssh keys as they may have some hardware dependence (not sure but that may have been the problem.)

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

Re: SSH Problem

Tue Dec 20, 2016 10:40 am

embeddedprogrammer wrote:[Evidently you cannot move a Raspian boot image from one PI to another without regenerating these ssh keys as they may have some hardware dependence (not sure but that may have been the problem.)
That is not true. The only part of hardware used when they're created is /dev/hwrng to generate some entropy.

I move SDCards from one Raspberry to another all the time, the only requirement is that they've got the right versions of bootcode.bin and start*.elf to match the hardware (those pieces are model dependent). Update that with sudo apt-get update && sudo apt-get -y dist-upgrade. If still you're unsure what you've got use sudo rpi-update to get the latest with a 4.4.38 kernel (not recommended because rpi-update can get experimental stuff).
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

Nfriedly
Posts: 5
Joined: Mon Jul 14, 2014 5:04 pm

Re: SSH Problem

Tue Jun 20, 2017 3:10 am

jojopi wrote:If you are running debian or raspbian on the Pi, try:

Code: Select all

sudo rm /etc/ssh/ssh_host_* && sudo dpkg-reconfigure openssh-server
(The "keygen -R" on the client is only necessary if you had connected successfully in the past. It tells the client that the server's host keys have changed.)
Thanks! I think the power got interrupted during my initial boot, and ssh not working was driving me crazy. That fixed it.

robpal
Posts: 3
Joined: Tue Mar 22, 2016 9:49 pm

Re: SSH Problem

Sun Jul 23, 2017 8:10 pm

Cornetto wrote:Thanks Mortimer and jojopi,
running

Code: Select all

sudo rm /etc/ssh/ssh_host_* 
and then

Code: Select all

sudo dpkg-reconfigure openssh-server
solved the problem!

Anyone care to explain what was wrong? So that I learnt something rather than just fixing it :D
Should I be adding the pi IP address to either of these commands? After either one I get the response:-

rm: /etc/ssh/ssh_host_*: No such file or directory

I'm using terminal from my macbook pro.

Cheers in advance.

Rob

robpal
Posts: 3
Joined: Tue Mar 22, 2016 9:49 pm

Re: SSH Problem

Sun Jul 23, 2017 8:24 pm

No worries, I sorted it using a random combination of trying every other combination that I'd already tried, and it still doesn't make sense.

I had to disable to SSH password and then use root@***.***.*.** followed by openelec as the password (even though I has disabled the password. The whole premise of the username being pi and the password being raspberry was what threw me off.

Anyway, I thought I'd mention this in case someone else needs this solution. I'll also be bookmarking this page for future reference if I forget how I solved it.

Return to “Beginners”

Who is online

Users browsing this forum: klricks, LorenAmelang, mediastore93 and 29 guests