How to change the default port 22 on the SSH server on Fedora 26

Change to root user


Edit the configuration file for the SSH server

nano /etc/ssh/sshd_config

Make the changes below to the fileAmendments are in amber. Here we have removed the # and specified a number for the port.

# 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
Port 2222
#AddressFamily any
#ListenAddress ::

فائل کو محفوظ کریں.

The port specified in the configuration file needs to be enabled in SELinux else you will get an error when restarting the SSH server service.

semanage port -a -t ssh_port_t -p tcp 2222

Restart the SSH server

service sshd restart

Other useful commands

Install semanage command

dnf -y install policycoreutils-python


If you are using a firewall you may also need to open the port

firewall-cmd --permanent --zone=public --add-port=2222/tcp

firewall-cmd --reload

جواب دیجئے