This is a Canonical Question about Connection Refused
We see a lot of questions to the effect
When I try to connect to a system I get a message
Connection refused
Why is this ?
This is a Canonical Question about Connection Refused
We see a lot of questions to the effect
When I try to connect to a system I get a message
Connection refused
Why is this ?
The message 'Connection Refused' has two main causes:
No process is listening.
This is by far the most common reason for the message. First ensure that you are trying to connect to the correct system. If you are then to determine if this is the problem, on the remote system run netstat or ss1 e.g. if you are expecting a process to be listening on port 22222
or
For OSX a suitable command is
If nothing is listening then the above will produce no output. If you see some output then confirm that it's what you expect then see the firewall section below.
If you don't have access to the remote system and want to confirm the problem before reporting it to the relevant administrators you can use tcpdump (wireshark or similar).
When a connection is attempted to an IP:port where nothing is listening, the response from the remote system to the initial SYN packet is a packet with the flags RST,ACK set. This closes the connection and causes the Connection Refused message e.g.
Note that tcpdump uses a . to represent the ACK flag.
Port is blocked by a firewall
If the port is blocked by a firewall and the firewall has been configured to respond with
icmp-port-unreachable
this will also cause a connection refused message. Again you can see this with tcpdump (or similar)Note that this also tells us where the blocking firewall is.
So now you know what's causing the Connection refused message you should take appropriate action e.g. contact the firewall administrator or investigate the reason for the process not listening.
1 Other tools are likely available.
For me on Debian 6 squeeze it was as simple as checking the SSH service:
And finding nothing existed (with the message
ssh: unrecognized service
) just installing the service:This also works if you're not getting an SFTP connection, as SFTP is a subset of SSH (whereas FTPS is a subset of FTP).