Skip to content

SELinux

1 post with the tag “SELinux”

A preliminary study on SELinux

Some operation commands about SELinux security context settings### 1. chcon- grammar ```

Section titled “Some operation commands about SELinux security context settings### 1. chcon- grammar ```”
chcon [选项]... 环境 文件...
chcon [选项]... [-u 用户] [-r 角色] [-l 范围] [-t 类型] 文件...
chcon [选项]... --reference=参考文件 文件...
```
  • Options ``` -h, –no-dereference:影响符号连接而非引用的文件。 –reference=参考文件:使用指定参考文件的安全环境,而非指定值。 -R, –recursive:递归处理所有的文件及子目录。 -v, –verbose:为处理的所有文件显示诊断信息。 -u, –user=用户:设置指定用户的目标安全环境。 -r, –role=角色:设置指定角色的目标安全环境。 -t, –type=类型:设置指定类型的目标安全环境。 -l, –range=范围:设置指定范围的目标安全环境。
restorecon [-iFnrRv] [-e excludedir ] [-o filename ] [-f filename | pathname...]
```
  • Options ``` -i:忽略不存在的文件。 -f:infilename 文件 infilename 中记录要处理的文件。 -e:directory 排除目录。 -R/-r:递归处理目录。 -n:不改变文件标签。 -o/outfilename:保存文件列表到 outfilename,在文件不正确情况下。 -v:将过程显示到屏幕上。 -F:强制恢复文件安全语境。

3. Semanage- Rules for automatically marking subsequent files under a certain path with security context

Section titled “3. Semanage- Rules for automatically marking subsequent files under a certain path with security context”
```
sudo semanage fcontext -a -t samba_share_t "/mnt/shared(/.*)?"
```
  • Delete the rule that automatically marks the security context of subsequent files under a certain path ``` sudo semanage fcontext - “/mnt/shared(/.*)?”

4. getebool- View all bool switches for SELinux

Section titled “4. getebool- View all bool switches for SELinux”
```
getsebool -a
```
```
setsebool -P <boolean_name> on/off
```

Among them,-Pis used for permanent modification.

6. Attention- It should be noted that any program running under SElinux needs to be supported by the corresponding SElinux security context, otherwise the operation will inevitably cause insufficient permissions.

Section titled “6. Attention- It should be noted that any program running under SElinux needs to be supported by the corresponding SElinux security context, otherwise the operation will inevitably cause insufficient permissions.”

[2].https://www.linuxprobe.com/chcon.html [3]. https://goto-linux.com/zh-cn/2020/6/13/%E5%A6%82%E4%BD%95%E5%9C%A8rhel-8-/-centos-8%E4%B8%8A%E5%AE%89%E8%A3%85%E5%92%8C%E9%85%8D%E7%BD%AEsamba/

[4]. Reverse-Proxy-with-Nginx-on-RHEL [5]. Install-Samba-on-RHEL-CentOS-Fedora [6]. Podman-Volumes-and-SELinux