Thursday, October 6, 2022
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

[[email protected] ~]# vim /etc/ssh/sshd_config
Port 2222

Save and Exit

Change Selinux Configuration

To change:
[[email protected] ~]# semanage port -a -t ssh_port_t -p tcp 2290
To list:
[[email protected] ~]# 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:

[[email protected] ~] yum provides /usr/sbin/semanage
[[email protected] ~] yum whatprovides /usr/sbin/semanage

From the output, we see that policycore-utils-python-utils provides this package. Install the policycoreutils-python-utils package:

[[email protected] ~] yum install policycoreutils-python-utils
[[email protected] ~]yum install policycoreutils-python

Add New Port to Firewall

To Add:
[[email protected] ~]# firewall-cmd –permanent --zone=public –add-port=2290/tcp
To Activate
[[email protected] ~]# firewall-cmd --reload

Restart SSHD Service to Activate New SSH Confiuration

[[email protected] ~]# systemctl restart sshd.service 

Step 5 : Show Running SSH Port

[[email protected] ~]# ss -tnlp | grep ssh

YOU CAN SUPPORT DEVNINJA WITH A CUP OF COFFEE

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

DevNinja
DevNinja
A systems engineer with experience in systems administration, cloud computing, systems deployment, virtualization, containers
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

4 × 5 =

- Advertisment -
Google search engine

Most Popular

Recent Comments