0

I have new RPi3 everything seems to work fine except the fact that I can not connect to it via ssh (from my laptop with Ubuntu 16.04). I have enabled the ssh on raspberry pi and I can establish the connection (see information below) but it gets closed immediately.

I do not know much about SSH so maybe I missed something obvious - but I could not find any solution.

When running ssh -vvv [email protected] I get:

OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "192.168.1.103" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.1.103 [192.168.1.103] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/mateusz/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mateusz/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mateusz/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mateusz/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mateusz/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mateusz/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mateusz/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mateusz/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.7p1 Raspbian-5+deb8u3
debug1: match: OpenSSH_6.7p1 Raspbian-5+deb8u3 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 192.168.1.103:22 as 'pi'
debug3: hostkeys_foreach: reading file "/home/mateusz/.ssh/known_hosts"
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
Connection closed by 192.168.1.103 port 22

When I try this locally on my Raspberry (connecting to localhost) I get a similar message.

5
  • Well I did not. mateusz is my user name on my laptop I do not know why raspberry wants to look for in on its own computer. What I run is ssh pi@pi's_ip eventually `ssh -v -I pi pi's_ip.
    – McCzajnik
    Jan 11, 2017 at 10:46
  • Ok, I have corrected the original message (sorry for the confusion). Is this what you meant by "full log"?
    – McCzajnik
    Jan 11, 2017 at 10:54
  • Done. Dos it make any sense now?
    – McCzajnik
    Jan 11, 2017 at 11:01
  • Well it is not exactly new - the system has been installed on an sd card few weeks ago and was used once on another RPi which stopped responding for some reason. No changes - It has been used only to boot it twice - but now I am starting to think that maybe I should reinstall it.
    – McCzajnik
    Jan 11, 2017 at 11:09
  • Have you checked the sshd logs? Are your permissions on ~/.ssh correct?
    – bobstro
    Sep 6, 2017 at 3:07

4 Answers 4

1

The next message in the ssh trace should be debug1: SSH2_MSG_KEXINIT received, so it is the Raspberry Pi who ends the connection. At this time Pi should also send its server keys for the client to authenticate.

Your log is consistent with the situation in which someone removed all the server keys from the Raspberry Pi. You can check this with:

$ ls /etc/ssh/ssh_host_*key*

/etc/ssh/ssh_host_dsa_key      /etc/ssh/ssh_host_ecdsa_key.pub    /etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_dsa_key.pub  /etc/ssh/ssh_host_ed25519_key      /etc/ssh/ssh_host_rsa_key.pub
/etc/ssh/ssh_host_ecdsa_key    /etc/ssh/ssh_host_ed25519_key.pub

If the result of ls is empty, you can get the SSHD functionality back by running:

dpkg-reconfigure openssh-server
0

You can try to remove the Raspberry Pi ssh key on the $HOME/.ssh/known_hosts file. At the first time, you can rename this file and try to connect again on the raspberry pi.

1
  • This would work if the SSH session proceeded with checking server keys and failed, but it's not even reaching that phase.
    – techraf
    Jan 11, 2017 at 13:44
0

Had the same problem. Inspired by @techraf I decided to delete the keys and rebuild it with dpkg-reconfigure openssh-server which solved the problem for me.

/var/log/auth.log contained error messages from sshd like: key_load_public: invalid format. Could not load host key: /etc/ssh/ssh_host_rsa_key before.

0

I had the same issue, and found out that out in the verbose mode that my ssh package tried to pass RSA key to authenticate, whereas the default setup on raspbian is to use password authentication

This was due to my ssh config I made before that disable password authentication.

To enable it you can pass the flag :

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no pi@yourPyIP

You can also change your ssh config file at $HOME/.ssh/config

Host mypi
    HostName raspberrypi.local # Or ip address 
    PreferredAuthentications=password
    PubkeyAuthentication=no
    User pi

and then just run ssh mypi

Your Answer

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

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