Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I have the following problem SSH "connection refused". It would work fine, but while I am working on the SSH, I would get "connection refused" and would have to re-connect (which does not occur for good 5-10 minutes). I have tried everything (restart linux, restart ssh) yet still does not help. I've checked var/log as well but nothing helpful in there...

NOTE: Interesting note I found is, when I try ssh to my external ip(277...), it goes to black cmd screen, I close this and try my 192.168.0.13 address and it lets me sign in.. but short while, again connection refused... Of course if I open my server and sudo sshd restart, my ssh "connection refused" goes away...

My ssh port is opened at 23, and I have it set on modem/router as well

sudpi@raspberrypi:~$ sudo netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1817/apache2
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      2227/vsftpd
tcp        0      0 127.0.0.1:3350          0.0.0.0:*               LISTEN      1784/xrdp-sesman
tcp        0      0 0.0.0.0:23              0.0.0.0:*               LISTEN      3115/sshd
tcp        0      0 0.0.0.0:3389            0.0.0.0:*               LISTEN      1781/xrdp
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      2397/mysqld

When I get disconnected, and log back in and check "WHO" I only see my previous connection, my root and the current connection

whopi@raspberrypi:~$ who  
pi       tty1         2013-01-28 09:20
pi       pts/0        2013-01-28 10:28 (192.168.0.12)
pi       pts/1        2013-01-28 10:32 (192.168.0.12)

This is what I have in my ssh_config that I have modified (SSH to 23 because rogers use 22...)

#   Port 23
...    
#Keep my damn connection alive!
KeepAlive yes
ServerAliveInterval 60

This is what I get when I run arp-scan

pi@raspberrypi:/etc$ sudo arp-scan -I eth0 -l | grep 192.168.0.13
192.168.0.13    a0:6c:ec:ec:bb:5b       (Unknown)

This part I found online that told me I should post the following two information

pi@raspberrypi:~$ ps afxu | grep sshd
root      2838  0.0  0.7   9800  3168 ?        Ss   10:27   0:00 sshd: pi [priv]                                                                                   
pi        2845  0.0  0.3   9800  1628 ?        S    10:28   0:00  \_ sshd: pi@pt                                                                                   s/0
root      2854  0.0  0.7   9800  3168 ?        Ss   10:32   0:00 sshd: pi [priv]                                                                                   
pi        2861  0.0  0.3   9800  1628 ?        S    10:32   0:00  \_ sshd: pi@pt                                                                                   s/1
root      2900  0.3  0.7   9800  3168 ?        Ss   10:44   0:00 sshd: pi [priv]                                                                                   
pi        2907  0.0  0.3   9800  1628 ?        S    10:44   0:00  \_ sshd: pi@pt                                                                                   s/2
root      2934  0.0  0.2   6204  1060 ?        Ss   10:45   0:00 /usr/sbin/sshd
root      2954  0.7  0.7   9800  3164 ?        Ss   10:45   0:00  \_ sshd: pi [p                                                                                   riv]
pi        2961  0.1  0.3   9800  1624 ?        S    10:46   0:00      \_ sshd: p                                                                                   i@pts/3
pi        2970  0.0  0.1   3536   796 pts/3    S+   10:46   0:00              \_                                                                                    grep sshd

EDIT: pi@raspberrypi:~$ ssh -vvv 192.168.0.13 (THIS might be long... Thank you Bart Friederichs)

pi@raspberrypi:~$ ssh -vvv 192.168.0.13 -p 23
OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012
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.0.13 [192.168.0.13] port 23.
debug1: Connection established.
debug1: SELinux support disabled
...
debug1: match: OpenSSH_6.0p1 Debian-3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-3
debug2: fd 3 setting O_NONBLOCK
debug3: put_host_port: [192.168.0.13]:23
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
...
debug1: Next authentication method: publickey
debug1: Trying private key: /var/www/.ssh/id_rsa
debug3: no such identity: /var/www/.ssh/id_rsa
debug1: Trying private key: /var/www/.ssh/id_dsa
debug3: no such identity: /var/www/.ssh/id_dsa
debug1: Trying private key: /var/www/.ssh/id_ecdsa
debug3: no such identity: /var/www/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
pi@192.168.0.13's password: - I TYPED PASSWORD -
...
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Linux raspberrypi 3.6.11+ #350 PREEMPT Mon Jan 7 21:51:11 GMT 2013 armv6l
share|improve this question

migrated from stackoverflow.com Jan 28 '13 at 16:05

This question came from our site for professional and enthusiast programmers.

    
Run netstat -tlpn as root (or with sudo) if you want to see the program names/PIDs. Moving SSH from its default port doesn't seem to be a good idea if you're not sufficiently familiar with Linux administration. –  Bruno Jan 28 '13 at 15:55
    
Lines started with # are comments, so in the line you specify the port 23 you have the # before, it will not be processed, and therefore it will use standard port (22). You can also have something in /etc/hosts.allow or /etc/hosts.deny controlling who can connect to sshd. Do you have checked if you don't have collision with ip address in your network? –  Pipe Jan 28 '13 at 19:16

4 Answers 4

Your sshd is listening on port 23, yet you are connecting to port 22 (ssh's default).

Try this:

  pi@raspberrypi:~$ ssh -vvv 192.168.0.13 -p 23

A "connection refused" error means the TCP layer in the kernel is not accepting any connections on that port. It has nothing to do with keeping alive or anything.

Also, you are using arp to find out stuff, but a better tool would be nmap. arp only tells you if the IP is in your broadcast domain, not if any ports are open.

share|improve this answer
    
Hello, Thank you for your reply, I've tried pi@raspberrypi:~$ nmap -bash: nmap: command not found... would I need to install it? and is there such for raspberry? Also thank you for the correction, I've edited with -p 23, but It doesn't have anything that looks out of place... –  Taehoon A Kim Jan 28 '13 at 16:02
    
nmap isn't really needed, just a handy tool. The update you made seems to have made it work? –  Bart Friederichs Jan 28 '13 at 16:25

I had the same problem and my solution was to disable and uninstall iptables.

run those commands:

(as sudoer)

iptables -F iptables -X iptables -t nat -F iptables -t nat -X iptables -t mangle -F iptables -t mangle -X iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT

sudo apt-get remove --purge iptables

share|improve this answer

with

sudpi@raspberrypi:~$ sudo netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1817/apache2
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      2227/vsftpd
tcp        0      0 127.0.0.1:3350          0.0.0.0:*               LISTEN      1784/xrdp-sesman
tcp        0      0 0.0.0.0:23              0.0.0.0:*               LISTEN      3115/sshd
tcp        0      0 0.0.0.0:3389            0.0.0.0:*               LISTEN      1781/xrdp
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      2397/mysqld
share|improve this answer
    
It is a good start to check what the problem is, but not enough to answer the question :-( –  Morgan Courbet Jan 29 '13 at 7:56

I had the same problem but is was resolved after I ran the command

sudo apt-get remove --purge iptables. and switching off the wireless connectivity.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.