已复制到剪贴板

semanage

semanage 命令行是一个管理 SELinux 策略的工具,可以用于更改 SELinux 的安全上下文和策略。它允许用户更改文件和进程的 SELinux 上下文,以及添加、删除和修改 SELinux 策略模块。

例子

  • /var/www 目录的 SELinux 安全上下文更改为 httpd_sys_content_t

    semanage fcontext -a -t httpd_sys_content_t "/var/www(/.*)?"
    restorecon -Rv /var/www
    
  • httpd 安全上下文更改为默认值:

    semanage fcontext -d -t httpd_sys_content_t "/var/www(/.*)?"
    restorecon -Rv /var/www
    
  • 启用 httpd_can_network_connect 权限:

    semanage port -a -t http_port_t -p tcp 8080
    semanage port -a -t http_port_t -p tcp 8888
    semanage boolean -m httpd_can_network_connect 1
    
  • 显示所有安装的 SELinux 模块:

    semanage module -l
    
  • 安装新的 SELinux 模块:

    semanage module -i /root/example.pp
    
  • 删除 SELinux 模块:

    semanage module -r example
    
  • 列出所有 SELinux 用户:

    semanage login -l
    
  • 添加一个新的 SELinux 用户:

    semanage login -a -s user_u -r s0-s0:c0.c1023 example_user
    
  • 删除一个 SELinux 用户:

    semanage login -d example_user