I followed step one of this guide to change the SSH port of my server: http://www.linux.com/archive/articles/61061

Now, when I try to log in to it again by typing

    ssh -p 1234 user@my-server

I get the message

    Connection closed by xxx.xxx.xxx.xxx

xxx being the IP address of my server. Not using the -p option of using any other port results in the answer

    ssh: connect to host my-server.com port xxx: Connection refused

How can I connect to it again? It's a Debian machine, in case that matters.

  • Not ap rogramming question, superuser.com perhaps? – Kurt Oct 13 '09 at 0:06
  • Is there a firewall involved? – Sinan Ünür Oct 13 '09 at 0:06
  • 1
    @Kurt I think ServerFault is more appropriate here because we are dealing with sshd and possibly a firewall. – Sinan Ünür Oct 13 '09 at 0:07
  • 1
    To debug ssh use -v -v -v -v -v -v – delete Oct 13 '09 at 0:10
  • 2
    For future reference, after you make any change to an important service like sshd, ensure that you establish a new session successfully before you close the current session. Restarting sshd does not affect existing ssh sessions, so if you've screwed it up you still have an active session to fix it. If you don't follow this practice, you'll probably going to have to get console access (which may require physical access depending on the hardware) to fix the problem. – James F Oct 13 '09 at 7:15

(As Kurt just mentioned) After having changed your default port in sshd_config, did you follow up by ensuring iptables was allowing inbound connections to your new port?

  • Don't post non-answer answers. – Sinan Ünür Oct 13 '09 at 0:09
  • 1
    Telling someone to verify their their firewall is open IS an answer. The phrasing used here is just a bit indirect... – Zoredache Oct 13 '09 at 0:21
  • Most likely this is the answer, that the server does not allow any inbound connections on that new port. Is there ANY chance I can get access to it? (physical access is not possible) – Manuel Meurer Oct 13 '09 at 18:21

Did you open a hole in the firewall?

  • Don't post non-answer answers. – Sinan Ünür Oct 13 '09 at 0:08
  • Don't be a jackass, that likely is the answer. – phoebus Oct 13 '09 at 3:21

First of all, ensure that SSH is indeed running on the new port. On the server machine, run

netstat -untap

Check that sshd is listening on port 1234.

Next, check that there are no firewall rules blocking port 1234 anywhere along the network between your client machine and the server (including on the client and the server). By default, your Debian firewall rules should be clear unless you have changed them. However, if there is any other network device sitting between your client and server, it can still block that port.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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