linux初级学习之selinux的管理2-10

seliunx管理
[root@localhost ~]# vim /etc/sysconfig/selinux ##在配置文件中将disabled改成enforcing 

[root@localhost ~]# getenforce                 ##查看状态
Enforcing                                      ##enforcing表示强制

[root@localhost ~]# ps auxZ | grep vsftpd      ##ps -Z来显示selinux上下文
system_u:system_r:ftpd_t:s0-s0:c0.c1023 root 849 0.0  0.0 52760   560 ?        Ss   00:55   0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 root 1889 0.0  0.0 112644 936 pts/1 R+ 00:58   0:00 grep --color=auto vsftpd

 [root@localhost pub]# touch westos
[root@localhost pub]# mv westos /var/ftp/pub/   
[root@localhost ~]# touch file
[root@localhost ~]# mv file /var/ftp/pub/
[kiosk@foundation66 Desktop]$ lftp 172.25.254.234     ##此时状态为enforcing,查看不到移动到本地的文件
lftp 172.25.254.234:~> ls
drwxrwxr-x    3 0        50             70 Apr 27 05:02 pub
lftp 172.25.254.234:/> cd /pub
lftp 172.25.254.234:/pub> ls
-rw-------    1 14       50       22105128 Apr 26 07:58 bigfile
-rw-------    1 14       50           2176 Apr 26 07:34 passwd
drwx------    2 14       50              6 Apr 26 03:31 redhat
lftp 172.25.254.234:/pub> quit

 [root@localhost pub]# setenforce  0   ##setenforce 0|1(0表示状态改为permissive,1表示改为enforcing)
[root@localhost pub]# getenforce 
Permissive
[kiosk@foundation66 Desktop]$ lftp 172.25.254.234 ##在permissive状态下可以看到移动到当前的文件westos和file
lftp 172.25.254.234:~> cd /pub
cd ok, cwd=/pub
lftp 172.25.254.234:/pub> ls
-rw-------    1 14       50       22105128 Apr 26 07:58 bigfile
-rw-r--r--    1 0        0               0 Apr 27 04:59 file
-rw-------    1 14       50           2176 Apr 26 07:34 passwd
drwx------    2 14       50              6 Apr 26 03:31 redhat
-rw-r--r--    1 0        0               0 Apr 27 05:01 westos
lftp 172.25.254.234:/pub> quit
[root@localhost pub]# ls -Z      ##显示selinux安全上下文,此时file和westos与别的文件格式不一致
-rw-------. ftp  ftp  system_u:object_r:public_content_t:s0 bigfile
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 file
-rw-------. ftp  ftp  system_u:object_r:public_content_t:s0 passwd
drwx------. ftp  ftp  system_u:object_r:public_content_t:s0 redhat
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 westos
[root@localhost pub]# chcon -t public_content_t  /var/ftp/pub/westos ##修该为westos的安全上下文
[root@localhost pub]# ls -Z                                         ##westos变为与其他文件一样的安全上下文,为操作的file格式不一致
-rw-------. ftp  ftp  system_u:object_r:public_content_t:s0 bigfile
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 file
-rw-------. ftp  ftp  system_u:object_r:public_content_t:s0 passwd
drwx------. ftp  ftp  system_u:object_r:public_content_t:s0 redhat
-rw-r--r--. root root unconfined_u:object_r:public_content_t:s0 westos


  
3.如何更改文件安全上下文
临时更改)
chcon -t 安全上下文    文件
chcon -t public_content_t /publicftp -R

永久更改)
semanage fcontext -l        ##列出内核安全上下文列表内容
semanage fcontext -a -t public_content_t '/publicftp(/.*)?'


restorecon -FvvR /publicftp/
• restorecon 是 policycoreutil 软件包的一部分
• semanage 是 policycoreutil-python 软件包的一部分
• semanage fcontext 可用与显示或修改 
  restorrecon 用来设置默认文件上下文的规则
• semanage fcontext 使用扩展正则表达式来指定路径和文件名。 
  fcontext 规则中最常用的扩展正则表达式是(/.*)?, 表示随意地匹配 / 后跟任何数量的字符
• semanage fcontext 将递归地与在表达式前面列出的目录以及该目录中的所有内容相匹配
[root@localhost mnt]# semanage fcontext  -a -t public_content_t  '/westos(/.*)?'
[root@localhost mnt]# semanage fcontext -l | grep westos
/westos(/.*)?                                      all files          system_u:object_r:public_content_t:s0 


[root@localhost mnt]# restorecon  -RvvF /westos/
restorecon reset /westos context unconfined_u:object_r:default_t:s0->system_u:object_r:public_content_t:s0
restorecon reset /westos/file1 context unconfined_u:object_r:default_t:s0->system_u:object_r:public_content_t:s0
restorecon reset /westos/file2 context unconfined_u:object_r:default_t:s0->system_u:object_r:public_content_t:s0
restorecon reset /westos/file3 context unconfined_u:object_r:default_t:s0->system_u:object_r:public_content_t:s0
restorecon reset /westos/file4 context unconfined_u:object_r:default_t:s0->system_u:object_r:public_content_t:s0
[root@localhost mnt]# touch /westos/file
[root@localhost mnt]# ls -Z /westos
-rw-r--r--. root root unconfined_u:object_r:public_content_t:s0 file
-rw-r--r--. root root system_u:object_r:public_content_t:s0 file1
-rw-r--r--. root root system_u:object_r:public_content_t:s0 file2
-rw-r--r--. root root system_u:object_r:public_content_t:s0 file3
-rw-r--r--. root root system_u:object_r:public_content_t:s0 file4

4.如何控制selinux对服务功能的开关
getsebool -a | grep 服务名称
getsebool -a | grep ftp
setsebool -P 功能bool值 on|off
setsebool -P    ftpd_anon_write on
[root@localhost mnt]# getsebool  -a | grep ftp
ftp_home_dir --> off
ftpd_anon_write --> off
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> off
ftpd_use_cifs --> off
ftpd_use_fusefs --> off
ftpd_use_nfs --> off
ftpd_use_passive_mode --> off
httpd_can_connect_ftp --> off
httpd_enable_ftp_server --> off
sftpd_anon_write --> off
sftpd_enable_homedirs --> off
sftpd_full_access --> off
sftpd_write_ssh_home --> off
tftp_anon_write --> off
tftp_home_dir --> off

[root@localhost mnt]# setsebool  -P ftp_home_dir 1  ##打开服务开关 1/on打开  0/off关闭
[root@localhost mnt]# getsebool  -a | grep ftp      ##ftp服务打开
ftp_home_dir --> on
ftpd_anon_write --> off
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> off
ftpd_use_cifs --> off
ftpd_use_fusefs --> off
ftpd_use_nfs --> off
ftpd_use_passive_mode --> off
httpd_can_connect_ftp --> off
httpd_enable_ftp_server --> off
sftpd_anon_write --> off
sftpd_enable_homedirs --> off
sftpd_full_access --> off
sftpd_write_ssh_home --> off
tftp_anon_write --> off
tftp_home_dir --> off



5.监控selinux的错误信息
setroubleshoot-server
• 必须安装 setroubleshoot-server 软件包 , 才能将SELinux 消息发送至 /var/log/messages

• etroubleshoot-server 侦听/var/log/audit/audit.log 中的审核信息并将简短摘要发送至 /var/log/messages
• 摘要包括 SELinux 冲突的唯一标识符 ( UUIDs ),可用于收集更多信息。 Sealert -l UUID 用于生成特定事件的报告。
 Sealert -a/var/log/audit/audit.log 用于在该文件中生成所有事件的报告







Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值