如何使用semanage管理SELinux安全策略
Semanage是用於配置SE Linux策略某些元素而無需修改或重新編譯策略源的工具。 這包括將Linux使用者名稱對映到SELinux使用者身份以及物件(如網路埠,介面和主機)的安全上下文對映。 |
簡介
Semanage是用於配置SELinux策略某些元素而無需修改或重新編譯策略源的工具。 這包括將Linux使用者名稱對映到SELinux使用者身份以及物件(如網路埠,介面和主機)的安全上下文對映。
實驗環境
Centos7.7作業系統
Selinux已經開啟
開啟方式:
[root@localhost ~]# sed -i '/^SELINUX/s/disabled/enforcing/g' /etc/selinux/config # 然後重啟一下作業系統 [root@localhost ~]# reboot # 重啟完成之後檢查一下是否是enforcing模式 [root@localhost ~]# getenforce Enforcing
常用引數
- port: 管理定義的網路埠型別
- fcontext: 管理定義的檔案上下文
- -l: 列出所有記錄
- -a: 新增記錄
- -m: 修改記錄
- -d: 刪除記錄
- -t: 新增的型別
- -p: 指定新增的埠是tcp或udp協議的,port子 命令下使用
- -e: 目標路徑參考原路徑的上下文型別,fcontext子 命令下使用
列出所有定義的埠
使用semanage port命令列出所有埠
[root@localhost ~]# semanage port -l SELinux Port Type Proto Port Number afs3_callback_port_t tcp 7001 afs3_callback_port_t udp 7001 afs_bos_port_t udp 7007 afs_fs_port_t tcp 2040 afs_fs_port_t udp 7000, 7005 afs_ka_port_t udp 7004 afs_pt_port_t tcp 7002 afs_pt_port_t udp 7002 afs_vl_port_t udp 7003 agentx_port_t tcp 705 agentx_port_t udp 705 amanda_port_t tcp 10080-10083 amanda_port_t udp 10080-10082 … …
列出指定的埠型別的埠
[root@localhost ~]# semanage port -l|grep -w http_port_t http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
通過查詢埠號來列出埠型別
[root@localhost ~]# semanage port -l|grep -w 53 dns_port_t tcp 53 dns_port_t udp 53 [root@localhost ~]# semanage port -l|grep -w 20 ftp_data_port_t tcp 20 [root@localhost ~]# semanage port -l|grep -w 21 ftp_port_t tcp 21, 989, 990
建立、新增、修改埠
通過下面的命令為http新增新埠
[root@localhost ~]# [root@localhost ~]# semanage port -a -t http_port_t -p tcp 8888 [root@localhost ~]# # 檢視新新增的埠 [root@localhost ~]# semanage port -l|grep -w 8888 http_port_t tcp 8888, 80, 81, 443, 488, 8008, 8009, 8443, 9000 # 也可以使用-C引數檢視自定義的埠號 [root@localhost ~]# semanage port -lC SELinux Port Type Proto Port Number http_port_t tcp 8888
新增一個範圍的埠
[root@localhost ~]# semanage port -a -t http_port_t -p tcp 11180-11188 [root@localhost ~]# [root@localhost ~]# semanage port -lC SELinux Port Type Proto Port Number http_port_t tcp 8888, 11180-11188
刪除埠
[root@localhost ~]# semanage port -d -t http_port_t -p tcp 8888 [root@localhost ~]# [root@localhost ~]# semanage port -d -t http_port_t -p tcp 11180-11188 [root@localhost ~]# # 檢視一下,已經沒有自定義的埠了 [root@localhost ~]# semanage port -lC
修改安全上下文
為samba共享目錄新增安全上下文
# 沒新增安全上下文之前是default_t [root@localhost ~]# ll -dZ /share/ drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /share/ [root@localhost ~]# semanage fcontext -a -t samba_share_t '/share(/.*)?' # 恢復檔案預設的安全上下文 [root@localhost ~]# restorecon -Rv /share restorecon reset /share context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:samba_share_t:s0 # 檢視一下資料夾已經變成samba_share_t了 [root@localhost ~]# ll -dZ /share drwxr-xr-x. root root unconfined_u:object_r:samba_share_t:s0 /share
為nfs共享目錄新增讀寫
[root@localhost ~]# ll -dZ /nfsshare/ drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /nfsshare/ [root@localhost ~]# [root@localhost ~]# semanage fcontext -a -t public_content_rw_t '/nfsshare(/.*)?' [root@localhost ~]# restorecon -Rv /nfsshare [root@localhost ~]# ll -dZ /nfsshare/ drwxr-xr-x. root root unconfined_u:object_r:public_content_rw_t:s0 /nfsshare/
總結
本文講述了新增、修改和刪除埠,修改安全上下文。如果你的系統有安裝桌面,可以安裝圖形化管理軟體 policycoreutils-gui來進行管理。
[root@localhost ~]# yum -y install policycoreutils-gui # system-config-selinux執行該命令開啟圖形化管理介面 [root@localhost ~]# system-config-selinux
原文地址: https://www.linuxprobe.com/semanage-selinux-policy.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31559985/viewspace-2674149/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用semanage管理SELinux安全策略Linux
- RHEL 6: semanage SELinux 命令找不到Linux
- SElinux配置與管理Linux
- SELinux: 如何讓selinux對某些命令放行,自定義selinux規則。Linux
- SELinux如何永久禁用Linux
- 使用netsh命令來管理IP安全策略(詳細介紹)
- SELinuxLinux
- selinux控制Linux
- switch_selinux.sh | 開啟或禁用SELinuxLinux
- 檢視 SELinux狀態及關閉SELinuxLinux
- SELinux Introduce - SELinux技術簡介(轉)Linux
- 檢視selinux的狀態以及關閉selinuxLinux
- 淺析SELinuxLinux
- 關閉selinuxLinux
- SELinux tipsLinux
- 【資訊保安】SELinuxLinux
- SeLinux分析工具Linux
- phpcms碎片管理如何使用呢?PHP
- SELinux簡單配置Linux
- rdp安全策略
- BYOD來襲:企業如何建立移動安全策略
- 使用sestatus命令來檢視SELinux的當前狀態Linux
- 什麼是seLinux?Linux關閉seLinux有什麼影響?Linux
- Linux中selinux是什麼意思?SELinux的主要作用有哪些?Linux
- 如何讓win10安全策略恢復系統預設設定_win10安全策略重置的方法Win10
- 瀏覽器安全策略說之內容安全策略CSP瀏覽器
- CentOS 8 禁用 SELinux 教程CentOSLinux
- selinux實戰手冊Linux
- selinux常用命令Linux
- Unable to load SELinux PolicyLinux
- RHEL5SELinux:AbenchmarkLinux
- PostgreSQL 行安全策略SQL
- 網路安全策略
- Oracle資料庫使用者安全策略功能介紹Oracle資料庫
- 在Linux中,SELinux工作原理是什麼?如何啟用/禁用?Linux
- 如何使用阿里雲管理控制檯阿里
- 如何使用 LVM 管理滴滴雲 EBSLVM
- React中如何使用Redux管理資料ReactRedux