Ubuntu 12.04 changing default ssh port: connection refused


I edited my /etc/ssh/sshd_config changing Port 22 to Port 1023. Restarted service and now I can’t connect.

Do I have to open port in firewall also? If so, how can I do this?

If I change back config to port 22 it works again.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

If you changed the port (in sshd_config file), opened the door on the firewall, you may need to update the selinux:

#semanage port -a -t ssh_port_t -p tcp 1023

Yes. If you’ve changed the port for SSH, you need to open that port in your iptables rules. You can also go ahead and close port 22.

root@graywoods:~# iptables-save <br># Generated by iptables-save v1.4.12 on Thu May 29 18:58:35 2014 <br>*filter <br>:INPUT ACCEPT [0:0] <br>:FORWARD ACCEPT [0:0] <br>:OUTPUT ACCEPT [255317:199083580] <br>-A INPUT -i lo -j ACCEPT <br>-A INPUT -d -j REJECT --reject-with icmp-port-unreachable <br>-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT <br>-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT <br>-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT <br>-A INPUT -j DROP <br>-A FORWARD -j DROP <br>COMMIT <br># Completed on Thu May 29 18:58:35 2014 <br>