【背景】
服务器中开通NFS服务供别人访问服务器上的文件
期间,NFS服务器端已经配置了写权限:
/home/share/image *(rw,sync)
然后客户端去mount:
mount -t nfs 121.41.120.185:/home/share/image /root/nfs_client_root/
可以看到文件了:
root@chantyou:nfs_client_root# ls -l
total 240
-rw-r–r-- 1 root root 70545 May 28 2013 mmexport1369703131812.jpg
-rw-r–r-- 1 root root 82168 Sep 12 2013 mmexport1378988706739.jpeg
-rw-r–r-- 1 root root 85510 Nov 18 2013 p_large_0fOT_43d9000068f01263.jpg
但是却无法写入:
root@chantyou:nfs_client_root# sudo touch test_client_write.txt
touch: cannot touch ‘test_client_write.txt’: Permission denied
【解决过程】
root@iZ23lqgttauZ:image# ls /home/share/ -l
total 4
drwxr-xr-x 2 root root 4096 Jul 23 15:16 image
root@iZ23lqgttauZ:image# ls /home/share/image/ -l
total 240
-rw-r–r-- 1 root root 70545 May 28 2013 mmexport1369703131812.jpg
-rw-r–r-- 1 root root 82168 Sep 12 2013 mmexport1378988706739.jpeg
-rw-r–r-- 1 root root 85510 Nov 18 2013 p_large_0fOT_43d9000068f01263.jpg
root@iZ23lqgttauZ:image#
好像:
NFS服务器端,没有给文件夹:
/home/share/image/
开通,g=group,o=other的写的权限。
所以去开通试试:
3lqgttauZ:image# chmod go+w /home/share/image/
root@iZ23lqgttauZ:image# ls /home/share/ -l
total 4
drwxrwxrwx 2 root root 4096 Jul 23 15:16 image
root@iZ23lqgttauZ:image#
然后NFS客户端再去试试写入是否可行:
真的可以了:
root@chantyou:nfs_client_root# sudo touch test_client_write.txt
root@chantyou:nfs_client_root#
【总结】
NFS的server端,虽然当前用户root,对于NFS共享出来的文件夹是有自己的写入权限,但是没有开通自己组group和其他人other的写权限:
root@iZ23lqgttauZ:image# ls /home/share/ -l
total 4
drwxr-xr-x 2 root root 4096 Jul 23 15:16 image
所以NFS客户端,去写入,应该属于other的权限,没法写出,出现Permission denied
解决办法是:
NFS客户端的共享出来的文件夹,开通other的写入权限:
root@iZ23lqgttauZ:image# chmod go+w /home/share/image/
root@iZ23lqgttauZ:image# ls /home/share/ -l
total 4
drwxrwxrwx 2 root root 4096 Jul 23 15:16 image
然后NFS的客户端就可以正常写入了:
root@chantyou:nfs_client_root# sudo touch test_client_write.txt
就是权限的问题。
方法二
加了no_root_squash,也可以解决问题。
no_root_squash: 有root的权限,不建议使用