This article will share how CentOS modifies the SSH port (how to modify the SSH port)
1. Log in to the centos server
2. Modify the SSH configuration file
vi /etc/ssh/sshd_config
3. Add a new port
# 查看当前ssh服务器端口号
netstat -tunlp | grep "ssh"
Opened for the first time and found that Port 22 is commented
Remove the previous #, and add a Port 202. The added listening port number should preferably be within the range of 10000~65535, that is, 2 to the 16th power. Doing this prevents port 202 from being connected and can also use port 22 to connect.
SSH related commands
# 重启sshd 服务:
systemctl restart sshd
# 查看sshd服务是否正常启动:
systemctl status sshd
# 检查端口是否处于监听状态:
netstat -ntulp | grep sshd
4. Firewall release
# 查看防火墙状态
firewall-cmd --state
# 防火墙如果关闭,则需要打开防火墙,执行命令:
# 打开防火墙
systemctl start firewalld
# 开机时启动firewall
systemctl enable firewalld.service
# 防火墙放行端口 202
firewall-cmd --zone=public --add-port=202/tcp --permanent
# 查看已开启端口
firewall-cmd --list-port
# 重启防火墙
systemctl restart firewalld
# 重启ssh服务
systemctl restart sshd
After the test is successful, just comment out port 22!