Sunday, February 25, 2024
Google search engine
HomeLinux TutorialsHow to Change SSH Port When Selinux is Enable on CentOS Linux...

How to Change SSH Port When Selinux is Enable on CentOS Linux 7

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


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online. to search or browse the published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or more ) as a token of appreciation.

Support Us

System & Network Administrator Ninja


Please enter your comment!
Please enter your name here

eleven − 9 =

- Advertisment -
Google search engine

Most Popular

Recent Comments