Linux CentOS修改SSH默认端口

一、切换到root权限

su - root

二、修改shhd_config

vi /etc/ssh/sshd_config

        按下i键开始编辑文本,在增加Port端口1024之后,esc,:wq!保存。以防万一,原SSH端口先不要删除。

三、增加linux端口 

        若是centos7系统,则需要安装semanage;centos8请直接跳到下一步。

yum install policycoreutils-python
yum provides semanage

        查询当前 ssh 服务端口

semanage port -l | grep ssh

        添加端口        

        向 Linux 中添加我们需要添加的ssh端口13389

semanage port -a -t ssh_port_t -p tcp 13389

        检测是否成功

semanage port -l | grep ssh

四、配置防火墙

        检查防火墙状态

firewall-cmd --state

         检测防火墙是否已经启用,启用返回值runing,反之,为not running。

        若没有启用,需要按照下面方法启用;若已启用,请跳到下一步。

systemctl start firewalld
systemctl enable firewalld

        查看防火墙的默认、活跃区域

firewall-cmd --get-default-zone
firewall-cmd --get-active-zones

         看两条命令的返回值是否含有public,有则为正确。

五、端口永久开放

firewall-cmd --permanent --zone=public --add-port=22/tcp
firewall-cmd --permanent --zone=public --add-port=13389/tcp

         防火墙重载

firewall-cmd --reload

        查看已暴露端口

firewall-cmd --permanent --list-port
firewall-cmd --zone=public --list-all

        重启SSH

systemctl restart sshd.service

六、禁用22端口

        修改shhd_config

vi /etc/ssh/sshd_config

       移除防火墙中的22端口

firewall-cmd --permanent --zone=public --remove-port=22/tcp

        重启防火墙并查看是否移除

firewall-cmd --reload
firewall-cmd --permanent --list-port

         重启系统

        在xshell中已经可以使用13389端口连接。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

殊彦_sy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值