Alternative SSH port
I configured SSH to use port 47378 (example). I have tried use iptables (
iptables -I INPUT -p tcp --dport 47378 -J ACCEPT) to open the port, but it doesn't seem to work. How would I go about using this port for SSH?
OS: CentOS Stream 9
✓ Best Answer
Some Possible Gotchas
- sshd needs to be restarted after edits are made in order to take effect:
# Restart sshd systemctl restart sshd.service # Verify that sshd is listening on the port you want ss -tulpn | grep sshd
- The line in
/etc/ssh/sshd_configwhere the port is configured, is commented out by default. There may also be a
ListenAddressdirective that is conflicting with your
# Show relevant lines from your /etc/ssh/sshd_config file cat /etc/ssh/sshd_config | grep -E '^#?(Port|ListenAddress)' /etc/ssh/sshd_config
iptables rules are not persistent by default
You may be using Cloud Firewalls and are blocking it there
There may be another rule in your iptables that is overriding the one that you mention:
# Check IP Tables iptables -L
- There may be a firewall on your local network or computer that is blocking port 47378.
- If you are using SELinux (some RedHat Distributions), you will need to add tcp port 47378 to your port contexts:
# Install the tools dnf update dnf install policycoreutils-python-utils # Show current port contexts semanage port -l | grep ssh # Update port context semanage port -a -t ssh_port_t -p tcp 47378 # Verify Changes semanage port -l | grep ssh # Open Port on Firewall firewall-cmd --add-port=47378/tcp --permanent firewall-cmd --reload # Restart sshd systemctl restart sshd
I configured SSH to use port 47378 (example).
Did you restart sshd:
sudo systemctl restart sshd