root下無法讀寫文件探究

1 在root權限下無法複製~/.gvfs/,也無法刪除~/.gvfs/
備份/home時出錯
/usr/share/backup# ./backup
  cp: 無法獲取"/home/hic/.gvfs" 的文件狀態(stat): 權限不夠
  tar: 2012-08-24_17_06_53:無法 stat: 沒有那個文件或目錄
  tar: 由於前次錯誤,將以上次的錯誤狀態退出
 
試圖給其加上可寫權限
~# chmod u+w .gvfs/
  chmod: 無法訪問".gvfs/": 權限不夠

顯示該目錄權限
~# ll -d .gvfs/
  ls: 無法訪問.gvfs/: 權限不夠

試圖以root刪除該目錄
~# rm -rf .gvfs/
  rm: 無法刪除".gvfs/": 是一個目錄


2 爲了進一步確認,我進到console,結果一樣 
試圖查看權限,發現爲亂碼,不能識別
~# ll | grep .gvfs/
  ls: 無法訪問.gvfs: 權限不夠
  d?????????  ? ?    ?        ?             ? .gvfs/

無法進入該目錄
~# cd .gvfs
  bash: cd: .gvfs: 權限不夠


3 我之前沒有使用rm的時候,它的屬性如下: 

 dr-x------  2 hic  hic      0  8月 24 16:14 .gvfs/
說明它是一個僅在hic下只讀的目錄。

4 然後我使用lsattr查看文件的第二擴展文件系統屬性,仍舊不行 

~# lsattr .gvfs 
  lsattr: 權限不夠 當嘗試對.gvfs進行stat調用時
~# lsattr -a .gvfs 
  lsattr: 權限不夠 當嘗試對.gvfs進行stat調用時


5 接着嘗試使用chattr改變屬性,仍不行 

~# chattr -i .gvfs 
  chattr: 權限不夠 當嘗試對.gvfs進行stat調用時


6 嘗試卸載~/.gvfs/,竟然成功 
按照網上的說明,使用mount卸載

~# umount .gvfs/

沒有報錯,說明卸載成功

7 ~/.gvfs是gvfs-fuse的掛載點 
下面是一段關於gvfs的介紹:

  What is the "fuse-daemon"?
  
  gvfs-fuse-daemon mounts your network connections as local file
  systems. The .gvfs dir is where any mounted network/other file systems
  are stored.
  
  For example: if you connect to you cellphone via the other:\\ prtocol,
  that directory wiil be mounted under the .gvfs dir so that legacy
  applications can access it.(like the terminal)


8 卸載之後 

~# ll | grep .gvfs/
  drwx------  2 hic  hic   4096  8月 21 19:15 .gvfs/

此時,已經可以使用root進入,也可以複製甚至刪除。


9 重啓之後此文件仍舊會出現 

但是它的權限仍舊和之前未卸載一樣,root權限下不能複製和刪除。

10 在root權限下仍舊不能查看 

~$ sudo -s
~# ll -d .gvfs/
  ls: 無法訪問.gvfs/: 權限不夠

11 在一般用戶權限下,卻能查看,複製甚至刪除 

~$ ll -d .gvfs/
  dr-x------ 2 hic hic 0  8月 24 18:43 .gvfs//

12 找到網上的一篇說明 

  There is FUSE virtual filesystem mounted at ~/.gvfs.  For the majority
  of filesystem acceses, permissions are ignored for the root
  user. However, FUSE virtual filesystems mounts are one of the rare
  exceptions. FUSE virtual filesystems normally restricted to user who
  mounted them. In this case , the gvfs-fuse-daemon command(run as part
  of your desktop session)created this mount, belonging to you, and
  no-one else can access it, including root.

它的意思就是,該文件可以在普通用戶權限下進行更改,但是除了該用戶之外,
其它用戶不可能對其進行讀取或者刪除,包括root也一樣。

13 小結

在備份/home的時候,不能用root,否則無法複製.gvfs/出現錯誤。正確的做法是,以普通權限備份,這樣就能避免該錯誤的發生。
發佈了79 篇原創文章 · 獲贊 20 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章