0

My raspberry pi randomly started refusing connections. After a reboot it allows connections, nothing has been changed in months with the config.

Here is the ssh -vvv output

OpenSSH_5.9p1 Debian-5ubuntu1.3, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.1.21 [192.168.1.21] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/matthew/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /home/matthew/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/matthew/.ssh/id_rsa-cert type -1
debug1: identity file /home/matthew/.ssh/id_dsa type -1
debug1: identity file /home/matthew/.ssh/id_dsa-cert type -1
debug1: identity file /home/matthew/.ssh/id_ecdsa type -1
debug1: identity file /home/matthew/.ssh/id_ecdsa-cert type -1ssh_exchange_identification: Connection closed by remote host

output of stat /home/matthew/.ssh/id_rsa

  File: ‘/home/matthew/.ssh/id_rsa’  
  Size: 1675            Blocks: 8          IO Block: 4096   regular file    
Device: 811h/2065d      Inode: 564404    Links: 1
Access: (0600/-rw-------)  Uid: ( 1000/ matthew)   Gid: ( 1000/ matthew)
Access: 2015-10-26 20:46:38.000000000 -0400
Modify: 2011-03-06 22:34:36.000000000 -0500
Change: 2011-03-06 22:34:36.000000000 -0500   
 Birth: -

output of stat /home/matthew/.ssh

  File: ‘/home/matthew/.ssh’  
  Size: 4096            Blocks: 8          IO Block: 4096   directory      
Device: 811h/2065d      Inode: 564461      Links: 2
Access: (0700/drwx------)  Uid: ( 1000/ matthew)   Gid: ( 1000/ matthew)
Access: 2015-10-27 11:14:03.000000000 -0400
Modify: 2015-09-04 11:55:54.000000000 -0400
Change: 2015-09-04 11:55:54.000000000 -0400 
 Birth: -

UPDATE

I found last night that ssh began refusing new connections while I had an active/functioning connection on going. I tried to open another ssh connection and it again was refused.

12
  • do you have enough memory? Space on card? It used to happen to me also but now I have really long uptime.
    – Jakuje
    Commented Oct 27, 2015 at 14:26
  • I have 10+GB free Commented Oct 27, 2015 at 14:28
  • Does /home/matthew/.ssh/id_rsa exist? Edit in the output from stat /home/matthew/.ssh/id_rsa and stat /home/matthew/.ssh.
    – goldilocks
    Commented Oct 27, 2015 at 14:43
  • Added the requested outputs Commented Oct 27, 2015 at 15:35
  • Do you connect with the right username. e.g. ssh [email protected]. If you connect with ssh 192.168.1.21 without a username then, a user matthew must exist on the raspi. The public key is taken from that user account. Perhaps you connect with a existing username when it worked and without a username when it refused connection. It's just a guess ;-). Commented Oct 28, 2015 at 12:08

3 Answers 3

1

So I believe I found the culprit. I don't know why it had any effect on eth0 but when I used to have my pi connected via WiFi I had this script running.

while true ; do
    if ifconfig wlan0 | grep -q "inet addr:" ; then
        sleep 60
    else
        echo "Network connection down! Attempting reconnection."
        ifup --force wlan0
        sleep 10
    fi
    done

This resolved some dropped WiFi issues. I'm not sure why all of a sudden it started causing refused ssh connections, after almost a year of using the hard wired connection. But its been chugging along all day now and has not refused a single connection.

1
  • 14 hours later, and still working with this fix. Commented Oct 29, 2015 at 11:44
0

Possible fix:

Remove your ~/.ssh folder, this will reset all of ssh's settings.

sudo rm -Rf ~/.ssh

1
0

Can you clarify what does "randomly" mean?

  1. It works after reboot for a while, and then it stops working forever

OR

  1. After a while it sometimes works, sometimes does not.

I would check:

  • is sshd running? $ ps aux | grep -i sshd
  • what happens if you start / restart sshd? $ sudo service ssh start and/or $ sudo service ssh restart
  • any significant entries in the following logs: /var/log/syslog, /var/log/auth.log that correlate to the connection failures ?
3
  • Random as in it works after reboot, then at some random time begins refusing connections until next reboot, sshd is running, no errors reported in auth.log or syslog. Auth.log does not even show the attempted login. Restarting ssh does not change anything as well Commented Oct 28, 2015 at 1:57
  • Could it be that there is some networking issue e.g. Raspberry Pi disconnects or changes the IP address after a while? E.g. when you have the failure to connect to sshd, can you connect to something else on the Pi? Can you ping the Pi? Commented Oct 28, 2015 at 2:54
  • Webserver on the pi works, when ssh doesn't. Pi is hardwired to the router with static IP configured on both the pi and my router. Commented Oct 28, 2015 at 11:26

Your Answer

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

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