chmod: changing permissions of 'xxx': Operation not permitted


1 root用戶也干不了的事情

  授權某文件時,提示 chmod: changing permissions of 'log': Operation not permitted錯誤.

  可能的原因: 此文件正在被鎖定,不允許操作或更改.chmod命令底層的實現是chattr命令,使用此命令后,可以使此文件被鎖定,無法進行添加/刪除/寫入等操作,就算root用戶也無法例外,熟悉chattr及lsattr命令即可解決此問題.

[root@web01 ~]# chattr +i /etc/passwd    #<==防止系統關鍵文件被篡改,就算是root也不例外
[root@web01 ~]# lsattr /etc/passwd       #<==查看此文件帶i,就是被鎖定了
----i----------- /etc/passwd                     
[root@web01 ~]# chattr -i /etc/passwd    #<==解鎖
[root@web01 ~]# lsattr /etc/passwd       #<==正常文件,root可以做任何操作
---------------- /etc/passwd
[root@web01 ~]# chattr +a /etc/passwd    #<==僅僅允許此文件進行追加操作,通常用於日志,如log
[root@web01 ~]# lsattr /etc/passwd
-----a---------- /etc/passwd
[root@web01 ~]# chattr -a /etc/passwd
[root@web01 ~]# lsattr /etc/passwd
---------------- /etc/passwd    

2 小結

  chattr , lsattr 在實際應用中對於服務器安全有重要的意義. 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM