Score:0

Unable to change SSH port on Almalinux/CentOS 8 with selinux present

in flag

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.

Score:0
cn flag
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 avatar
in flag
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 [email protected] -p 23498`
Sergey Kozharinov avatar
cn flag
Check `netstat -lnptu | grep 23498`. Also check for any errors in `journalctl -e`.
Rashiq avatar
in flag
`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.
Sergey Kozharinov avatar
cn flag
Check that port 23498 is allowed through ufw. Also check that firewalld is not installed.
Rashiq avatar
in flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.