Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to connect to my server from the internet, I always get:

debug2: ssh_connect: needpriv 0
debug1: connect to address XX.XX.XX.69 port 22: Connection refused
ssh: connect to host XX.XX.XX.69 port 22: Connection refused

But from the local area network with 192.168.... all works fine.

Why this difference?

Note I tested with telnet XX.XX.XX.69. Port 22 is open.

share|improve this question
What is in the auth.log (or similar). You might want to make ssh server more verbose while trouble shooting. – jippie Oct 21 '12 at 18:23
What is the contents of the files /etc/hosts.deny and /etc/hosts.allow? Please update your question with the results. What do you see when telnetting from remote location into your box on port 22? Same for local telnet. – jippie Oct 21 '12 at 18:26
the both .deny and .allow are empty – Yurij73 Oct 21 '12 at 19:19
Did you put some allow/disallow-rules into the sshd_config? Is there a local firewall active? – Nils Oct 21 '12 at 19:29
from local and from remote location telnet XX.22 say the same OpenSSH ... bla-bla It is strange but just now my ssh works!!!. Nothing changed but i tryed to conect by other way from local network to my external IP and get: The authenticity of host 'XX.XX.XX.69 (XX.XX.XX.69)' can't be established. RSA key fingerprint is ....04:b4:da. Are you sure you want to continue connecting (yes/no)? y Please type 'yes' or 'no': yes Warning: Permanently added ' ' (RSA) to the list of known hosts So it work now. All solved without config enchantments – Yurij73 Oct 21 '12 at 19:33

“Connection refused” indicates that there is a firewall preventing connections or that there is no server listening on that port on the target host. A few possible reasons why your telnet attempt would have worked but not your ssh attempt:

  • The SSH daemon was not running when you tried with ssh.
  • You didn't try telnet and ssh from the same machine, and SSH connections are accepted from the machine you ran ssh on but not from the machine you ran telnet.
  • The SSH server requires port knocking. The telnet attempt happened soon enough after the port knocking, but the knock's validity had expired when you tried ssh.
  • The IP address of the server is dynamic and was assigned to another machine at the time.
  • Something about the network configuration changed between your attempts. Most likely on your router, but possibly on your client machine, on the server or any place in between. It's difficult to speculate without having more information about your network setup.
share|improve this answer

Your Answer


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

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