selinux= 为 disabled_修改Linux SSH的端口与SELinux究竟是什么

最近,发现修改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 命令快速切换。

a94d839fa46c32b89dcc767824b2656b.png

修改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,成功

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值