linux selinux 端口,修改LinuxSSH的端口与SELinux究竟是什么

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

SELinux简介

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

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

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

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

disabled:关闭 SELinux。

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

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

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

cc855d076e5690bd318e925afd00dec6.png

修改ssh端口方法

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

修改文件/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

之后需要重启。

临时修改:

使用命令setenforce 0

附:

setenforce 1 设置SELinux 成为enforcing模式

setenforce 0 设置SELinux 成为permissive模式

之后修改/etc/ssh/sshd_config:

Port 2223

重启ssh服务systemctl restart ssh,成功

文章来源: www.oschina.net,作者:zhxhash,版权归原作者所有,如需转载,请联系作者。

原文链接:https://my.oschina.net/u/3747772/blog/3138544

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值