SSH service runs on 22 port number. You can change this port number for security. If you use Oracle Linux 7, Centos 7 or Red Hat Linux 7 versions, you can change port number with below operations. If selinux is enabled, you have to add new port number to selinux configuration because of the fact that selinux allows only 22 port number for ssh connections.
Change Port Number
[root@devninja ~]# vim /etc/ssh/sshd_config Port 2222 Save and Exit
Change Selinux Configuration
To change: [root@devninja ~]# semanage port -a -t ssh_port_t -p tcp 2290 To list: [root@devninja ~]# semanage port -l | grep ssh
Install semanage (optional)
When you are configuring SSH in order to change default port 22 into some random number, you will probably be prompted with an error that says: semanage command not found. This is quick way to successfully change SSH port. Try these two following commands:
[root@devninja ~] yum provides /usr/sbin/semanage [root@devninja ~] yum whatprovides /usr/sbin/semanage
From the output, we see that policycore-utils-python-utils provides this package. Install the policycoreutils-python-utils package:
[root@devninja ~] yum install policycoreutils-python-utils [root@devninja ~]yum install policycoreutils-python
Add New Port to Firewall
To Add: [root@devninja ~]# firewall-cmd –permanent --zone=public –add-port=2290/tcp To Activate [root@devninja ~]# firewall-cmd --reload
Restart SSHD Service to Activate New SSH Confiuration
[root@devninja ~]# systemctl restart sshd.service
Step 5 : Show Running SSH Port
[root@devninja ~]# ss -tnlp | grep ssh