1

I am trying to change the SSH port on a VPS using Almalinux. I followed this guide but have not been able to.

These are the output I receive when try to SSH using both 22 and the new port respectively.

ssh: connect to host XXX.XXX.XXX.XXX port 22: Connection timed out
ssh: connect to host XXX.XXX.XXX.XXX port 23498: Connection timed out

Here is the port declaration in my /etc/ssh/sshd_config.

...
Port 23498 22
...

Running semanage port -l | grep ssh gives the following output.

ssh_port_t                     tcp      23498, 22

Restarting using service sshd restart with the new port yields the following output.

Redirecting to /bin/systemctl restart sshd.service
Job for sshd.service failed because the control process exited with error code.
See "systemctl status sshd.service" and "journalctl -xe" for details.

Here is the output of systemctl status sshd.service.

● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2022-02-25 17:26:08 CET; 34s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 25872 ExecStart=/usr/sbin/sshd -D $OPTIONS $CRYPTO_POLICY (code=exited, status=255)
 Main PID: 25872 (code=exited, status=255)

Feb 25 17:26:08 xxx.xxx.xxx systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
Feb 25 17:26:08 xxx.xxx.xxx systemd[1]: sshd.service: Failed with result 'exit-code'.
Feb 25 17:26:08 xxx.xxx.xxx systemd[1]: Failed to start OpenSSH server daemon.

Changing the port causes normal SSH to break as well. Commenting out the Port in the sshd_config and restarting sshd allows access via SSH again. I have also tried reinstalling the openssh-server after changing the ports but to no avail. The ports are allowed through the uncomplicated firewall. Any help is highly appreciated.

Rashiq
  • 115
  • 4

1 Answers1

0
Port 23498
Port 22

instead of

Port 23498

Edit:

It seems firewalld was running as well as ufw. Having that unconfigured meant my ports were getting blocked.

Rashiq
  • 115
  • 4
  • I split the port declaration in the `sshd_config`. Port 22 is now working but port 23498 is not - `ssh: connect to host XXX.XXX.XXX.XXX port 23498: Connection timed out`. Here is the SSH command I'm using `ssh someusername@XXX.XXX.XXX.XXX -p 23498` – Rashiq Feb 25 '22 at 16:52
  • Check `netstat -lnptu | grep 23498`. Also check for any errors in `journalctl -e`. – Sergey Kozharinov Feb 25 '22 at 17:01
  • `command not found: netstat`. It says the following that are relevant to ports: ` Server listening on :: port 22.`; ` Server listening on :: port 23498.`. I can't find anything else that is relevant or has `error` written anywhere. – Rashiq Feb 25 '22 at 17:08
  • Check that port 23498 is allowed through ufw. Also check that firewalld is not installed. – Sergey Kozharinov Feb 25 '22 at 17:20
  • The ports are allowed through ufw. Firewalld was running. I guess it was blocking the ports since I didn't do anything about that. I can now SSH through both ports. Thank you so much. – Rashiq Feb 25 '22 at 19:22