SELINUX,SELinux 基礎命令

 2023-11-09 阅读 29 评论 0

摘要:檢查SELinux是否已經啟用. [root@localhost?~]#?sestatusSELinux?status:??disabled ? 常用命令如下: sestatus 查詢系統的selinux目 前的狀態 SELINUX?selinuxenabled 查詢系統的selinux支 援是否有啟用 setenforce 設定selinux運 作狀態 getsebool 列出所有selinux bo

檢查SELinux是否已經啟用.

[root@localhost?~]#?sestatus
SELinux?status:??disabled

?

常用命令如下:

sestatus

查詢系統的selinux目 前的

SELINUX?selinuxenabled

查詢系統的selinux支 援是否有啟用

setenforce

設定selinux運 作

getsebool

出所有selinux bool數值清單表與內容

shell sed命令,setsebool??????

設定selinux bool數值內容

chcon

檔案目security context

restorecon

檔案目的預設的security context

linux命令及說明。fixfiles

修正檔案目的預設的security context

semanage

SELiux policy程式

secon

檢視程、檔案等等項目的SELinux context

shell基本命令的使用?audit2why

檢視SELinux audit訊息內容

sealert

SELinux 訊息診斷用戶端程式


下面列出幾個常用的:

1、sestatus工具
查詢系統的selinux 目前的狀態
例如:root@monitor:~# sestatus
SELinux status:???????????????? enabled
SELinuxfs mount:??????????????? /selinux
Current mode:?????????????????? permissive
Mode from config file:????????? permissive
Policy version:???????????????? 21
Policy from config file:??????? targeted

2、selinuxenabled工具
檢查系統selinux是否開啟,是通過返回值進行判斷selinux是否已經啟動,0:表示已經啟動selinux;1:表示已經關閉selinux
例如:selinuxenabled ; echo?,返回的結果為:1

3、setenforce工具
功能:設定切換selinux的運行狀態(0或者1),前提是開啟了selinux,同時這種切換只對當前有效,如果重新啟動的話,就沒有效了(注意:如果關閉了selinux,那么就必須配置/etc/selinux/config文件)
語法:setenforce [ Enforcing | Permissive | 1 | 0 ]
說明如下:
enforcing 或者1,表示開啟強制模式
permissive 或者0,表示開啟警告但是無限制模式
例如:下面這個例子
root@monitor:~# sestatus | grep -i mod
Current mode:?????????????????? permissive
Mode from config file:????????? permissive
root@monitor:~# setenforce 1
root@monitor:~# sestatus | grep -i mod
Current mode:?????????????????? enforcing
Mode from config file:????????? permissive

4、getsebool與setsebool工具

說明:SELinux規范了許多boolean數值清單檔案,提供開啟或關閉功能存取項目,而這些值都存放在/selinux/booleans/目錄內相關檔案,這些檔案里的值只有兩種:1(啟用)或 0(關閉)

1)getsebool
說明:列出所有selinux bool數值清單列表與內容
使用方式:getsebool [ -a ]
例如以下范例:
#getsebool ftpd_disable_trans
ftpd_disable_trans --> off
#getsebool -a
NetworkManager_disable_trans --> off
allow_cvs_read_shadow --> off
allow_daemons_dump_core --> on
allow_daemons_use_tty --> off
allow_execheap --> off
allow_execmem --> on
allow_execmod --> off
..........

2)setsebool
說明:設定selinux bool數值清單列表與內容
使用方式:setsebool [ -P ]? boolean value | bool1=val1 bool2=val2 bool3=val3......
參數配置: -P表示設定該項目永久套用
使用范例:
setsebool ftpd_disable_trans=on ( on 或者 1 )
setsebool -P ftpd_disable_trans=off ( off 或者 0 )

5、chcon
說明:變更檔案目錄的security context
使用方式:
chcon [OPTION]... CONTEXT FILE...
chcon [OPTION]... --reference=RFILE FILE...
參數如下:
-u USER:set user USER in the target security context
-r ROLE:set role ROLE in the target security context
-t TYPE:set type TYPE in the target security context
范例:
chcon -t var_t /etc/vsftpd/vsftpd.conf
chcon --reference=/var/www/html index.html
注意事項:若是變更于目錄上,后續于該目錄內建立的檔案目錄會套用目錄本身type設定

6、restorecon
說明:恢復檔案目錄的預設的security Context
規格來源:/etc/selinux/<POLICY>/contexts/files/目錄內的file_contexts與file_contexts.local
常用參數如下:
-r | -R:包含子目錄與其下檔案目錄
-F:恢復使用預設的項目(就算是檔案符合存取規范)
-v:顯示執行過程
使用方式:restorecon [FRrv] [-e excludedir ] pathname... ]
使用范例如下:
restorecon /etc/ntp.conf
restorecon -v /etc/ntp.conf
restorecon -v -F /etc/ntp.conf
手動配置新增恢復規則
1)檔案名稱
/etc/selinux/<POLICYTYPE>/contexts/files/file_contexts.local
2)新增配置范例
/var/ftp(/.*)??? system_u:object_r:public_content_t
3)注意
可以使用semanage程式來維護會比較方便

7、fixfiles
說明:修正檔案目錄的預設的security Context,依據/etc/selinux/<POLICY>/contexts/files/內相關檔案修正
使用方式:
fixfiles { check | restore|[-F] relabel } [[dir] ... ]
fixfiles -R rpmpackage[,rpmpackage...] { check | restore }
參數:
-R:使用指定的rpm 套件所提供的檔案清單
使用范例:
fixfiles check /etc
fixfiles restore /etc
fixfiles -F relabel /
fixfiles -R setup check

8、audit2why
說明:檢視SELinux audit訊息內容,提供檢視/var/log/audit/audit.log內的記錄資訊說明
使用范例:audit2why <? /var/log/audit/audit.log
注意:需要搭配啟動auditd服務程式一起使用

9、sealert
說明:SELinux 訊息診斷用戶端程序
參數如下:
-H, --html_output:使用網頁格式輸出(搭配 -a or -l 使用)
-l, --lookupid ID:檢視指定ID的警示訊息
使用范例:
sealert -l xxxxx-xxxxx-xxxx
sealert -H -l xxxxx-xxxxx-xxxx > output.html
注意:需要搭配setroubleshoot服務一起使用
setroubleshoot服務啟動后,會依據audit服務提供的資訊給予適當問題診斷,然后輸出于/var/log/messages,該檔案內會有相關輸出資訊提供除錯檢視

10、semanage
說明:selinux policy維護工具
使用方式:semanage { login | user | port | interface | fcontext | translation} -l [-n]
使用范例:
semanage login -l
semanage user -l
semanage port -l
semanage port -a -t http_port_t -P tcp 81
semanage fcontext? -a? -t??? httpd_sys_Context_t?? "/home/users/(.+)/public_html(/.*)?“

11、secon
說明:檢視程式、檔案與使用者等相關SELinux Context
使用方式:
secon [-hVurtscmPRfLp] [CONTEXT]
secon [--file] FILE | [--link] FILE | [--pid] PID
參數:
-u, --user:show the user of the security context
-r, --role:show the role of the security context
-t, --type:show the type of the security context
-f, --file FILE:gets the context from the specified file FILE
-p, --pid PID:gets the context from the specified process PID
使用范例:
secon -u
secon -r
secon -t
secon --file /etc/passwd
secon --pid <pid>

linux最常用命令。?

轉:http://www.cnblogs.com/zgx/archive/2011/08/31/2160330.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/168649.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息