python中os.path.isdir,os.path.isfile()函数用法

  python中os.path.isdir,os.path.isfile()函数用法

  文件的防火墙属性

  1 .临时更改文件的类型属性

  文件类型属性不正确是常见防火墙拒绝访问的主要原因

  1 )更改文件的防火墙属性:

  [root @ localhost ~]#触摸测试。文件# #新文件

  显示[root @ localhost ~]# ls-ztest。文件# #文件的防火墙属性

  -rw-r-r-r .root roun configured _ u:object _ r:admin _ home _ t:s0测试。文件

  [ root @ localhost~] # chcon-t更改samba _ share _ ttest.file # #文件的默认防火墙属性

  [root @ localhost ~]# ls-ztest。文件

  -rw-r-r-r .root roun configured _ u:object _ r:samba _ share _ t:s0测试。文件

  [root @ localhost ~]# restore con-f-vt est。文件# #将更改的防火墙属性还原为默认属性

  恢复控制复位/根/测试。filecontextunconlined _ u:object _ r:samba _ share _ t:s0-system _ u:obo对象

  [root @ localhost ~]# ls-ztest。文件

  -rw-r-r-r .root root system _ u:object _ r:admin _ home _ t:s0 test。文件

  2 )更改目录的防火墙属性(所有操作与文件相比,表示递归的"-R "都增加了一个) :

  [root@localhost ~]# mkdir /web

  [root @ localhost ~]# touch/web/file { 1,2 }

  [ root @ localhost~]显示# ls-dz/web # #目录的防火墙属性

  drwxr-xr-x . rootrounconfigured _ u:object _ r:default _ t:s0/web

  [root @ localhost ~]# ls-zxd Yb/web/# #显示目录中文件的防火墙属性

  -rw-r-r-root roun configured _ u:object _ r:default _ t:s0 file 1

  -rw-r-r-rootrounconfinted _ u:object _ r:default _ t:s0文件2

  [root @ localhost ~]# chcon-r-thttpd _ sys _ content _ t/web/# #临时修改目录的防火墙属性为httpd _系统_内容_ t

  [root@localhost ~]# ls -dZ /web/

  dwxr-xr-x . root root root unconfixed _ u:object _ r:httpd _ sys _ content _ t:s0/web/

  [root @ localhost ~]# ls-zxd Yb/web/

  -rw-r-r-r .root roun configured _ u:object _ r:httpd _ sys _ content _ t 3360 s0文件一

  -rw-r-r-r .root roun configured _ u:object _ r:httpd _ sys _ content _ t 3360 s0文件2

  [root @ localhost ~]# restore con-r-v/web/# #恢复默认防火墙属性

  restorecon reset/webcontext unconlined _ u:object _ r:httpd _ sys _ content _ t:s0-un confined _ u 3360 object

  restorecon reset/web/file 2 context unconfixed _ u:object _ r:httpd _ sys _ content _ t:s0-_ nconfined _ r

  restorecon reset/web/file 1 context unconfixed _ u:object _ r:httpd _ sys _ content _ t:s0-_ nconfined _ r

  [root @ localhost ~]# ls-zxd Yb/web/

  -rw-r-r-root roun configured _ u:object _ r:default _ t:s0 file 1

  -rw-r-r-rootrounconcf

  ined _ u:object _ r:default _ t:s0文件2

  [root@localhost ~]# ls -dZ /web/

  drwxr-xr-x . root root root root unconlined _ u:object _ r:default _ t:s0/web/

  2.永久修改文件的类型属性

  永久修改文件及目录的类型属性使用下列命令:

  上下文的语义-{ a d l m }[-frst]filespec # #-a增加、-d删除、-l显示、-m修改

  还原重组蛋白-v文件规范##由于"语义fcontext命令只是将属性定义项加载到

  "/etc/selinux/targeted/contexts/files/file _ contexts。本地"文件中,

  使用该命令才是将文件的防火墙属性永久地修改。

  1)文件的防火墙属性修改

  [root @ localhost tmp]#触摸测试。文件

  [root@localhost tmp]# ls -Z测试。文件

  -rw-r-r-r .root root un confined _ u:object _ r:user _ tmp _ t:s0 test。文件

  [root @ localhost tmp]# yum安装策略coreutils-python # #安装语义管理管理工具提供软件

  [root @ localhost tmp]# semanage f context-a-t samba _ share _ t/tmp/test。文件# #将测试文件的防火墙属性设置为"桑巴共享"

  [root @ localhost tmp]# ls-Z/tmp/test。文件编号测试文件的防火墙属性未发生变化

  -rw-r-r-r .root root un confined _ u:object _ r:user _ tmp _ t:s0/tmp/test。文件

  [root @ localhost tmp]# restore con-v/tmp/test。文件# #使语义管理设置的防火墙属性永久的生效

  restorecon reset /tmp/test.file上下文un collined _ u:object _ r:user _ tmp _ t:s0-un collined _ u:object _ r:samba _ share _ t:s0

  [root @ localhost tmp]# ls-Z/tmp/test。文件编号测试文件的防火墙属性已改

  -rw-r-r-r .root root un confined _ u:object _ r:samba _ share _ t:s0/tmp/test。文件

  2)目录的防火墙属性修改:(完成后目录下新建的文件自动继承防火墙属性)

  [root@localhost ~]# mkdir /html

  [root @ localhost ~]# touch/html/file { 1,2}

  [root@localhost ~]# ls -dZ /html

  drwxr-xr-x . root root root root unconlined _ u:object _ r:default _ t:s0/html

  [root @ localhost ~]# ls-zxdyb/html/

  -rw-r-r-r .root root un confined _ u:object _ r:default _ t:s0 file 1

  -rw-r-r-r .root root un confined _ u:object _ r:default _ t:s0 file 2

  [root @ localhost ~]# semanage f context-a-t httpd _ sys _ content _ t /html(/.*)?##正则表达式"/html(/.*)?"表示/html目录及其中的任何文件或子目录

  [root @ localhost ~]# restore con-R-v/html/# #使语义管理设置的防火墙属性永久的生效

  restorecon重置/html上下文un collined _ u:object _ r:default _ t:s0-un collined _ u:object _ r:httpd _ sys _ content _ t:s0

  restorecon reset/html/file 2 context un confined _ u:object _ r:default _ t:s0-un confined _ u:object _ r:httpd _ sys _ content _ t:s0

  restorecon reset/html/file 1 context un confined _ u:object _ r:default _ t:s0-un confined _ u:object _ r:httpd _ sys _ content _ t:s0

  [root @ localhost ~]# ls-zxdyb/html/# #验证修改结果

  -rw-r-r-r .root root un confined _ u:object _ r:httpd _ sys _ content _ t:s0 file 1

  -rw-r-r-r .root root un confined _ u:object _ r:httpd _ sys _ content _ t:s0 file 2

  [root@localhost ~]# ls -dZ /html/

  drwxr-xr-x . root root root un conlined _ u:object _ r:httpd _ sys _ content _ t:s0/html/

  3)如果要恢复/html的文件属性可使用下列命令:

  [root @ localhost ~]# semanage f context-d /html(/.*)?##删除自定义的防火墙属性

  [root @ localhost ~]# restore con-F-R-v/html/# #永久生效

  restorecon reset/html context unconlined _ u:object _ r:httpd _ sys _ content _ t:s0-system _ u:object _ r:default _ t:s0

  restorecon reset/html/file 2上下文unconlined _ u:object _ r:httpd _ sys _ content _ t:s0-system _ u:object _ r:default _ t:s0

  restorecon reset/html/file 1 context unconlined _ u:object _ r:httpd _ sys _ content _ t:s0-system _ u:object _ r:default _ t:s0

  [root @ localhost ~]# ls-zxdyb/html # #验证文件的防火墙属性已经从" httpd_sys_content_t "改为默认的默认_t

  -rw-r-r-r .root root system _ u:object _ r:default _ t:s0 file 1

  -rw-r-r-r .root root system _ u:object _ r:default _ t:s0 file 2

  [root@localhost ~]# ls -dZ /html

  drwxr-xr-x . root root root root system _ u:object _ r:default _ t:s0/html

  4)文件_t与默认_t

  文件_t:文件没有防火墙属性

  默认_t:文件或目录的防火墙属性与文件上下文配置文件定义的模式不匹配

  两种的类型的文件或目录,受限制的域的程序均不能访问

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: