CentOS 7.2 换SSH端口

作者: kx叔 | 来源:发表于2018-04-23 20:22 被阅读16次
    1. 查看系统版本
      lsb_release -a
      cat /etc/os-release
      cat /etc/redhat-release
      uname -r
    2. 更新系统
      yum update
    3. 编辑ssh配置文件
      vi /etc/ssh/sshd_config
    4. 安装 SElinux

    据说这玩意很智能
    yum provides semanage
    yum -y install policycoreutils-python

    1. 白名单端口
      semanage port -a -t ssh_port_t -p tcp 2200

    如果执行失败
    使用 vi /etc/selinux/config
    设置 SELINUX=permissive

    1. 重启系统
      init 6
    2. 查看状态
      sestatus
    3. 查看端口
      semanage port -l | grep ssh
    4. 重启服务
      systemctl restart sshd

    据说 semanage是禁不掉22端口的,测试命令:semanage port -d -t ssh_port_t -p tcp 22

    1. 防火墙安装
      yum install iptables-services
    2. 修改防火墙
      vi /etc/sysconfig/iptables

    添加端口允许
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 2200 -j ACCEPT

    1. 重启防火墙
      systemctl restart iptables.service
    2. 查看历史
      history
    3. 记得去云服务器管理后台「安全组规则」打开对应端口。

    相关文章

      网友评论

        本文标题:CentOS 7.2 换SSH端口

        本文链接:https://www.haomeiwen.com/subject/ywxrlftx.html