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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章