0

For security reasons I changed the port for an ssh login to a different port number. But as soon as I do and try to reconnect, I get a 'Connection timed out error'. Once I switch back to port 22 it all works fine. This is what I have done so far:

  1. Logged in to my VPS via using ssh [email protected].
  2. In /etc/ssh/ I changed the sshd_config file to set the port to 717.
  3. Restarted the ssh daemon using: sudo systemctl restart sshd
  4. Verified that the ssh daemon is up and running using systemctl status sshd
  5. Verified that port 22 isn't working anymore by trying to login on a 2nd terminal like in 1.
  6. This led to the expected ssh: connect to host vps.ip.address port 22: Connection refused
  7. Tried to login via ssh using the port 717: ssh [email protected] -p 717
  8. After some time I get as response: ssh: connect to vps.ip.address port 717: Connection timed out
  9. Still in my active terminal session on my VPS verifying that server is correctly listening on port 717 : sudo grep Port /etc/ssh/sshd_config. The output was:
Port 717
#GatewayPorts no

  1. Checked the firewall settings to make sure there is no blocking of port 717: sudo iptables -L
  2. This returned:
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  

  1. checked the /var/log/auth.log output to verify that is still listening on port 717:
Mar 13 08:18:20 localhost sshd[4883]: Server listening on 0.0.0.0 port 717.`
`Mar 13 08:18:20 localhost polkitd(authority=local): Unregistered Authentication Agent for unix-process:4863:4345392 (system bus name :1.35, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
  1. changed the port back to port 22 in /etc/ssh/sshd_config and restarted the ssh daemon
  2. login from a 2nd terminal via ssh just like under 1.
  3. successfully logged in again.
3
  • what port does netstat show Mar 14, 2023 at 9:25
  • 2
    This sounds like a firewall from your VPS provider. What provider are you using? Check their cloud settings, there may be some page where you set up the firewall rules (that is, before the traffic even reaches your VPS). Also, regarding security, you don't gain much by changing the port. Best is to disable password authentication and use a private/public key pair for access.
    – gepa
    Mar 14, 2023 at 9:28
  • @gepa That was it. Thanks a lot. I am using ionos as cloud provider and by default they only allow port 22, 80 and 443. I didn't look up their default firewall settings Mar 14, 2023 at 9:47

0

You must log in to answer this question.

Browse other questions tagged .