日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux中没有semanagea安装包,如何使用semanage管理SELinux安全策略

發布時間:2025/3/19 linux 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux中没有semanagea安装包,如何使用semanage管理SELinux安全策略 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

導讀

Semanage是用于配置SE

策略某些元素而無需修改或重新編譯策略源的工具。 這包括將Linux用戶名映射到SELinux用戶身份以及對象(如網絡端口,接口和主機)的安全上下文映射。

簡介

Semanage是用于配置SELinux策略某些元素而無需修改或重新編譯策略源的工具。 這包括將Linux用戶名映射到SELinux用戶身份以及對象(如網絡端口,接口和主機)的安全上下文映射。

實驗環境

7.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

本文原創地址:

總結

以上是生活随笔為你收集整理的linux中没有semanagea安装包,如何使用semanage管理SELinux安全策略的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。