美文网首页
修改Linux SSH的端口与SELinux究竟是什么

修改Linux SSH的端口与SELinux究竟是什么

作者: 干货满满张哈希 | 来源:发表于2019-12-07 11:02 被阅读0次

    最近,发现修改ssh端口后,无法启动ssh服务,发现是SELinux限制了这个,此篇文章简单记录下。

    SELinux简介

    SELinux 主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)。

    SELinux 有三种工作模式,分别是:

    1. enforcing:强制模式。违反 SELinux 规则的行为将被阻止并记录到日志中。

    2. permissive:宽容模式。违反 SELinux 规则的行为只会记录到日志中。一般为调试用。

    3. disabled:关闭 SELinux。

    SELinux 工作模式可以在 /etc/selinux/config 中设定。

    如果想从 disabled 切换到 enforcing 或者 permissive 的话,需要重启系统。反过来也一样。

    enforcing 和 permissive 模式可以通过 setenforce 1|0 命令快速切换。

    image

    修改ssh端口方法

    首先需要关闭SELinux,有两种方法:

    1. 修改文件/etc/selinux/config
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=permissive
    # SELINUXTYPE= can take one of three values:
    #     targeted - Targeted processes are protected,
    #     minimum - Modification of targeted policy. Only selected processes are protected. 
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted
    
    

    之后需要重启。

    1. 临时修改:
    使用命令setenforce 0
    
    

    附:
    setenforce 1 设置SELinux 成为enforcing模式
    setenforce 0 设置SELinux 成为permissive模式

    之后修改/etc/ssh/sshd_config:

    Port 2223
    

    重启ssh服务systemctl restart ssh,成功

    相关文章

      网友评论

          本文标题:修改Linux SSH的端口与SELinux究竟是什么

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