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

ぃ、小莉子 提交于 2019-12-07 20:44:09

最近,发现修改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,成功

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!