Connect to Raspberry Pi over ssh: connection refused (from putty)

  • I have a raspberry running raspbian, and I want to connect over SSH, but something is happening.

    On the raspberry I have run nmap and port 22 says: OPEN; the ssh process is running and fine.

    But I can't connect from my windows 8.1 machine with putty, I just get connection refused.

    Can anyone give me any pointers?

    Edit: forgot to mention that I can both ping it and I have checked raspi-config, and it seems normal.

    I had some trouble resolving dependencies with apt-get, but I reinstalled resolvconf, and that fixed it.

    EDIT2: It also didn't work while disabling the Windows Firewall.

    EDIT3: I can ssh the pi from the pi.

    EDIT4: I just found out that my raspberry and windows box have the same ip... what?

    Sure it is connected to the internet? Try in the command line following command : `ifconfig wlan0` . Is there a _real_ IP adress in the line `inet addr`?

    Can you ping from Windows machine to your Pi?

    Check if the ssh starts in boot from '/etc/init/' and check 'sudo raspi-config', you might have disabled ssh

    See edit for more info.

    I had a similar issue...finally just restarted my router (after losing 1.5 hrs debugging), and boom, magically it all works again! Symptoms were weird: all devices had internet, but could not talk to each other, and SSH refused. Restarting router fixed whatever the issue was...so it turns out it wasn't even on the PCs.

  • ptf

    ptf Correct answer

    5 years ago

    So, I figured it out.

    A long time ago I assigned an IP to my pi on the router, binding its mac address to the IP.

    It so happened yesterday that I had the same IP when I needed the pi again. So I probably tried to connect to my windows machine from my windows machine because of the identical IP's.

    What fixed it was this in cmd (on my windows box):

    ipconfig /release

    ipconfig /renew

    yay, finally

    Worth noting that the latest Raspbian ships with ssh disabled in the config.

    @Eddie You saved my life man!!!!!

  • Raspberry changed something since November 2016

    here is the noob instruction to get this problem fixed

    sudo su
    raspi-config
    

    1) Choose first 'update'

    2) In advanced options -> expand_root file system

    3) interfacing options -> ssh [enable]

    4) change_locale [your country-UTF8] and if you still here, it's good to change the timezone as well

    5) change the default password (don't be lazy, just do it :)

    Please - add "change default user password" to the above list. This is probably the reason they turned it off by defaut.

    @TomaszGandor ty that's a good one

  • It might be an issue with wrong SSH key pair matching. Your client stores SSH keys of previous sessions. So if you've SSH'ed in the past with this same client to another device (or same Raspberry but with different build) on the same IP, the keys on both sides don't match. Solution: delete the keys on your client.

    Putty stores SSH keys in the registry: HKEY_CURRENT_USER\SoftWare\YOU\PuTTY\SshHostKeys. If you aren't using Putty have a look at %USERPROFILE%\ssh or %USERPROFILE%\.ssh. If you're using OSX, have a look at ~/.ssh/known_hosts

    This was a clean install on the pi, and I havent used any ssh keys with putty on this machine. This is getting difficult.

  • It might be the windows firewall that is blocking the outbound ssh connection. Make sure port 22 is allowed out of your windows machine.

    Ah, I didn't mention that I disabled the Windows Firewall as well, but with no luck.

    On the Pi can you `ssh localhost`

    Yeah, that works.

    And for kicks `ifconfig` on the Pi and `ipconfig` on windows show that both systems are on the same network?

    I'm not at home right now, but I remember both having the same default gateway, both being plugged into the same switch with ethernet cable, and though I didn't check my windows box's ip, the pi's ip looked like it should.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM