1. 程式人生 > 其它 >root許可權下修改檔案許可權遇到 chmod: changing permissions of '***': Operation not permitted

root許可權下修改檔案許可權遇到 chmod: changing permissions of '***': Operation not permitted

一、問題描述

眾所周知,在linux系統中,許可權最大的是root,但凡修改涉及到系統本身的重大許可權的操作,都需要root的許可權才能操作。但是有些時候也有root幹不了的事情。

比如:

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

二、問題背景

有時候需要修改檔案的許可權,但是即使在root下使用chmod命令也不一定能成功更改,有時也會遇到Operation not permitted的問題。

一般,Linux下root使用者的許可權是最大 (Linux下UID數值越小的使用者,許可權越大,可以看到最小值為0,即root使用者)

但是在使用chmod改變檔案許可權的時候,即使在root使用者下,也會遇到operation not permitted的問題。

其實chmod的底層實現是chattr命令,用此命的功能更為強大,甚至可以鎖定檔案,即使root使用者也操作不了此檔案。

三、解決方案

lsattr可用來檢視檔案的屬性:

lsattr filename

如果檔案屬性中有i與a,或者有其中的一個

可以使用chattr去掉這屬性:

chattr -ia filename

此時再次使用chmod命令即可更改檔案的許可權。

該方法對於檔案目錄同樣適用,但是檔案目錄使用lsattr命令檢視屬性的時候並沒有反應,但是使用chattr命令去掉ia屬性之後,能夠成功使用chmod更改許可權。

如果想要恢復ia屬性,使用:

chattr +ia filename

轉:https://blog.csdn.net/SweeNeil/article/details/103237214/

https://www.cnblogs.com/cpl9412290130/p/11592803.html