I have a small question regarding SSH
How do I change the port for ssh and allow the new port in firewalld. How do I then close the old port 22 in firewalld?
Kind regards
I have a small question regarding SSH
How do I change the port for ssh and allow the new port in firewalld. How do I then close the old port 22 in firewalld?
Kind regards
firewall-cmd
or with files in /etc/firewalld/*
. See Configuring firewalls and packet filters Red Hat Enterprise Linux 9 | Red Hat Customer Portal
How to configure SSH to use a non-standard port with SELinux set to enforcing | TechRepublic is another one that gives instructions for the ssh port and firewall.
That says sudo nano /etc/ssh/sshd_config
Fine for el8, but el9 has a new shiny:
sudo nano /etc/ssh/sshd_config.d/00-myport.conf
The statements in /etc/ssh/sshd_config.d/00-myport.conf
do override statements
in /etc/ssh/sshd_config
and you can later easily see what customizations you
have done, rather than asking âWhat did I edit in /etc/ssh/sshd_config
?â
Ah, thanks for that. As the one Alma Iâm using regularly is on an older machine that wonât take Alma9, I wasnât aware of that. (My other installs are on laptops or vms, where I havenât tried to change the default port). So, I learned something this morning, thanks to you.
Used me of these two commands for when I changed the gate in the file sshd_config
semanage port -a -t ssh_port_t -p tcp 2021
Semanage port -m -t ssh_port_t -p tcp 2021
Then I restarted the service for firewalld
sudo systemctl restart firewalld
Then it worked great.
By the way, how do I Put this post as solved?
This is âfor the recordâ.
The following description is in the /etc/ssh/sshd_config file for el9:
# To modify the system-wide sshd configuration, create a *.conf file under
# /etc/ssh/sshd_config.d/ which will be automatically included below
Include /etc/ssh/sshd_config.d/*.conf
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER