如何在CentOS 7上添加SSH端口

修改文件/etc/ssh/sshd_config

1
2
Port 22  #去掉这行开头的#号
Port 22222 #添加一行

firewall添加端口

1
2
firewall-cmd --zone=public --add-port=22222/tcp --permanent
firewall-cmd --reload

修改selinux

如果没有安装policycoreutils-python需要先安装:

1
yum -y install policycoreutils-python

安装完成后添加22222端口:

1
semanage port -a -t ssh_port_t -p tcp 22222

查看是否添加成功:

1
2
[root@vm ~]# semanage port -l | grep ssh
ssh_port_t tcp 22222, 22

重启ssh服务

1
systemctl restart sshd

检查ssh服务是否监听22222端口:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@vm ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-07-23 15:26:10 CST; 24s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 17854 (sshd)
Tasks: 1
CGroup: /system.slice/sshd.service
└─17854 /usr/sbin/sshd -D

Jul 23 15:26:10 vm systemd[1]: Starting OpenSSH server daemon...
Jul 23 15:26:10 vm sshd[17854]: Server listening on 0.0.0.0 port 22222.
Jul 23 15:26:10 vm sshd[17854]: Server listening on :: port 22222.
Jul 23 15:26:10 vm sshd[17854]: Server listening on 0.0.0.0 port 22.
Jul 23 15:26:10 vm sshd[17854]: Server listening on :: port 22.
Jul 23 15:26:10 vm systemd[1]: Started OpenSSH server daemon.
Hint: Some lines were ellipsized, use -l to show in full.

可见看到ssh服务监听22222和22端口。

作者

Junle

发布于

2019-07-23

更新于

2024-03-22

许可协议

评论