zoukankan      html  css  js  c++  java
  • Locked the resolv.conf via command chattr

    Sometime we would found that a file cannot be modified with the root permission,the cause may be is this file has been locked by the 'chattr' command.'chattr' is a useful command,and some of its function depends on the linux kernel version.We can impove the system secrity by excute the 'chattr' command,but it does not make sence on the all of  directories.'chattr 'can not protect the directory /, /dev,/tmp,/var

    Command'lsattr' canbe use to dispaly the file attributes about 'chattr'.

    Otherwise,we use command 'chmod' to change the R/W/X permission,but chatttr is an access to the  phycial  level properties

    chattr userguide:

    chattr [ -RVf ] [ -v version ] [ mode ] files

    the most important part is [mode],[mode] is consis of the "+-="和"ASacDdIijsTtu", is for contorlling the file attributes

    + :在原有参数设定基础上,追加参数。
    - :在原有参数设定基础上,移除参数。
    = :更新为指定参数设定。
    A:文件或目录的 atime (access time)不可被修改(modified), 可以有效预防例如手提电脑磁盘I/O错误的发生。
    S:硬盘I/O同步选项,功能类似sync。
    a:即append,设定该参数后,只能向文件中添加数据,而不能删除,多用于服务器日志文件安全,只有root才能设定这个属性。
    c:即compresse,设定文件是否经压缩后再存储。读取时需要经过自动解压操作。
    d:即no dump,设定文件不能成为dump程序的备份目标。
    i:设定文件不能被删除、改名、设定链接关系,同时不能写入或新增内容。i参数对于文件 系统的安全设置有很大帮助。
    j:即journal,设定此参数使得当通过mount参数:data=ordered 或者 data=writeback 挂 载的文件系统,文件在写入时会先被记录(在journal中)。如果filesystem被设定参数为 data=journal,则该参数自动失效。
    s:保密性地删除文件或目录,即硬盘空间被全部收回。
    u:与s相反,当设定为u时,数据内容其实还存在磁盘中,可以用于undeletion。
    各参数选项中常用到的是a和i。a选项强制只可添加不可删除,多用于日志系统的安全设定。而i是更为严格的安全设定,只有superuser (root) 或具有CAP_LINUX_IMMUTABLE处理能力(标识)的进程能够施加该选项。

    Example:

    1、
    use chattr command to propect the key file not to be changed
    #chattr +i /etc/resolv.conf

    if want to unlock the file 

    #chattr -i /etc/resolv.conf

    check the file properties

    # lsattr /etc/resolv.conf
    ----i-------- /etc/resolv.conf

    2、if want to add the data to a file ,but cannot delete the file ,can use +a attributes.It often apply on the log file

    #chattr +a /var/log/messages

  • 相关阅读:
    excel表格的jar包
    mac和jar的关系
    BAT批处理文件入门-笔记
    没看完_perl的find模块很全面的讲解!!
    perl怎么拷贝一个文件到另一个文件夹中或者怎么拷贝文件夹到另一个文件夹
    perl 中用到的-*的具体解释,方便查看
    perl语言的笔记--啥是mkpath
    剑指哦佛_我的第一篇博客,哦耶
    ajax创建万能的XmlHttpRequest对象
    动态实例化窗体
  • 原文地址:https://www.cnblogs.com/yongdaiblog-201409/p/6714020.html
Copyright © 2011-2022 走看看