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

Operators are cutting marketing expenses, so how can agents survive?

Although the scale of mobile phone users has long...

Interpretation of the 2017 Global Data Breach Cost Research Report

In early July, the 2017 Global Cost of Data Breac...

Internet of Things Lecture: NB-IoT\eMTC\LoRa have their own division of labor

In 2018, the year of the explosion of IoT connect...

Technology trends to watch in 2018

In the coming 2018, artificial intelligence (AI),...

ICMP/ARP protocol analysis and ARP spoofing

ICMP ICMP (Internet Control Message Protocol) is ...

Facebook launches new AI project to learn from videos

On March 30, according to foreign media reports, ...

When will the price of NB-IoT modules drop below 20 yuan?

The cost of NB-IoT, especially the module cost, h...

Some Discussions on the Transmission Network in DCI

Preface The exploration of DCI technology has bee...

A Brief Analysis of Data Flow Technology in Data Centers

What is the most valuable thing in a data center?...

How is the UK train network going digital?

[51CTO.com Quick Translation] Dennis Rocks, produ...