## 1、修改SSH端口 编辑sshd配置文件 ``` sudo vi /etc/ssh/sshd_config ``` 找到以下行 ``` #Port 22 ``` 修改为新的端口 ``` Port 33000 ``` ### 2、修改SELinux配置,为SSH增加新端口 查看当前配置 ``` $ sudo semanage port -l | grep ssh ssh_port_t tcp 22 ``` 增加新的端口 ``` sudo semanage port -a -t ssh_port_t -p tcp 33000 ``` 检查配置 ``` $ sudo semanage port -l | grep ssh ssh_port_t tcp 33000, 22 ``` ### 3、开启防火墙端口 ``` sudo firewall-cmd --add-port=33000/tcp --permanent sudo firewall-cmd --reload ``` [scode type="yellow"] 如果 firewalld 服务尚未启动,则需要在防火墙启动前通过编辑配置文件`/etc/firewalld/zones/public.xml`的方式添加端口,示例如下: ``` Public For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. ``` 添加完成后即可启动服务 ``` systemctl start firewalld ``` [/scode] ### 4、重启服务 ``` sudo systemctl restart sshd ``` Loading... ## 1、修改SSH端口 编辑sshd配置文件 ``` sudo vi /etc/ssh/sshd_config ``` 找到以下行 ``` #Port 22 ``` 修改为新的端口 ``` Port 33000 ``` ### 2、修改SELinux配置,为SSH增加新端口 查看当前配置 ``` $ sudo semanage port -l | grep ssh ssh_port_t tcp 22 ``` 增加新的端口 ``` sudo semanage port -a -t ssh_port_t -p tcp 33000 ``` 检查配置 ``` $ sudo semanage port -l | grep ssh ssh_port_t tcp 33000, 22 ``` ### 3、开启防火墙端口 ``` sudo firewall-cmd --add-port=33000/tcp --permanent sudo firewall-cmd --reload ``` <div class="tip inlineBlock warning"> 如果 firewalld 服务尚未启动,则需要在防火墙启动前通过编辑配置文件`/etc/firewalld/zones/public.xml`的方式添加端口,示例如下: ``` <?xml version="1.0" encoding="utf-8"?> <zone> <short>Public</short> <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> <service name="ssh"/> <service name="dhcpv6-client"/> <service name="cockpit"/> <port port="33000" protocol="tcp"/> <forward/> </zone> ``` 添加完成后即可启动服务 ``` systemctl start firewalld ``` </div> ### 4、重启服务 ``` sudo systemctl restart sshd ``` Last modification:December 26, 2024 © Allow specification reprint Like 如果觉得我的文章对你有用,请随意赞赏