How to change ssh port in CentOS7.*

How to change ssh port in CentOS7.*

I checked the port modification records in the simple security settings of VPS in the tribe, and they are still in the centos6.* era. The port modification in CentOS7.* has relatively more steps and is more troublesome. In order to avoid forgetting and having to look for it occasionally, I recorded it down for my own convenience.

1. Add a new port

This step is the same as centos6.*, modify the configuration file.

 [root@ ~]# vi /etc/ssh/sshd_config

Find #Port 22, remove the # in front and add a new line Port 1234 (1234 is the new port, specify it yourself), then save and exit.

2. Open new ports in the firewall

 [root@ ~]# firewall-cmd --zone=public --add-port=1234/tcp --permanent
#1234 refers to the new port [root@~]# firewall-cmd --reload

If you are trying it for a short period of time, you can also turn off the firewall.

3. Add ssh port to SELinux

 [root@ ~]# yum provides semanage
#Install management tools [root@ ~]#yum -y install policycoreutils-python
#Install dependent packages [root@ ~]#semanage port -l | grep ssh
#Query ssh port [root@ ~]#semanage port -a -t ssh_port_t -p tcp 1234
#Add ssh port to SELinux [root@ ~] #systemctl restart sshd.service
#Restart sshd service

This step can also turn off SElinux

 [root@ ~]# vi /etc/selinux/config

Change SELINUX=enforcing to SELINUX=disabled, save the settings, and reboot.

<<:  RepriseHosting: $27.97/month-L5640, 16G memory, 1TB hard disk, 10TB monthly traffic, Seattle data center

>>:  Hostodo: 36% off Spokane VPS, West Coast data center, starting at $12 per year

Recommend

Pour some cold water on the "feverish" 5G concept: the market is far from mature

The popularity of 5G networks, 5G mobile phones, ...

Wi-Fi in an IoT World

We’ve written quite a bit about Wi-Fi, but what I...

In the next ten years, the WiFi module market will usher in rapid growth

According to market research by Market.us, the gl...

Practical VPC Network Planning on the Cloud

What is VPC Virtual Private Cloud (VPC) is a priv...

5G in numbers: 5G trends revealed by statistics in the first half of 2021

[[420577]] 2021 marks the second anniversary of t...

The difference and application of single-mode fiber and multi-mode fiber

Fiber optics can transmit data faster and over lo...

How SD-WAN is reconfiguring enterprise services

As software-defined wide area networks (SD-WAN) h...

VULTR adds its 30th data center in the world: Osaka, Japan

It has been more than half a year since I last sh...

Ma Xiaofang from Xunlei: I yearn for a manager who is like a "stabilizing force"

[51CTO.com original article] In order to pay trib...

7 key features of 5G mobile phones

1. Support high-power terminals Compared with bas...

How to better migrate data centers

Migrating a data center is no small feat, and it ...

The slowdown in 5G construction is not a problem, 5G application is the key

China Mobile said that the bidding in July has be...