Nfs – CentOS 5.4 NFS v4 client file permissions differ from original files & NFS Share file contents

chmodchownnfspermissions

Having a strange problem with NFS share and file permissions on the 1 out of the 2 NFS clients, web1 has file permissions issues but web2 is fine. web1 and web2 are load balanced web servers.

So questions are:

  1. how do I ensure NFS share file contents retain the same permissions
    for user/group as the original files on web1 server like they do on web2 server ?
  2. how do I reverse what I did on web1, i tried unmount command and said command not found ?

Information:
I'm using 3 dedicated server setup. All 3 servers CentOS 5.4 64bit based.

servers are as follows:

  • web1 – nfs client with file permissions issues
  • web2 – nfs client file permissions are OKAY
  • db1 – nfs share at /nfsroot

web2 nfs client was setup by my web host, while web1 was setup by me.

I did the following commands on web1 and it worked with updating db1 nfsroot share at /nfsroot/site_css with latest files on web1 but the file permissions don't stick even if i use tar with -p command to perserve file permissions ?

cd /home/username/public_html/forums/script/
tar -zcp site_css/ > site_css.tar.gz
mount -t nfs4 nfsshareipaddress:/site_css /home/username/public_html/forums/scripts/site_css/ -o rw,soft 
cd /home/username/public_html/forums/script/
tar -zxf site_css.tar.gz

But checking on web1 file permissions no longer username user/group but owned by nobody ? but web2 file permissions correct ? This is only a problem for web1 while web2 is correct ? Looks like numeric ids aren't the same ? Not sure how to correct this ?

web1 with incorrect user/group of nobody

ls -alh /home/username/public_html/forums/scripts/site_css
total 48K
drwxrwxrwx 2 nobody nobody 4.0K Feb 22 02:37 ./
drwxr-xr-x 3 username username 4.0K Feb 22 02:43 ../
-rw-r--r-- 1 nobody nobody    1 Nov 30  2006 index.html
-rw-r--r-- 1 nobody nobody 5.8K Feb 22 02:37 style-057c3df0-00011.css
-rw-r--r-- 1 nobody nobody 5.8K Feb 22 02:37 style-95001864-00002.css
-rw-r--r-- 1 nobody nobody 5.8K Feb 18 05:37 style-b1879ba7-00002.css
-rw-r--r-- 1 nobody nobody 5.8K Feb 18 05:37 style-cc2f96c9-00011.css

web1 numeric ids

ls -n /home/username/public_html/forums/scripts/site_css
total 48
drwxrwxrwx 2  99  99 4096 Feb 22 02:37 ./
drwxr-xr-x 3 503 500 4096 Feb 22 02:43 ../
-rw-r--r-- 1  99  99    1 Nov 30  2006 index.html
-rw-r--r-- 1  99  99 5876 Feb 22 02:37 style-057c3df0-00011.css
-rw-r--r-- 1  99  99 5877 Feb 22 02:37 style-95001864-00002.css
-rw-r--r-- 1  99  99 5877 Feb 18 05:37 style-b1879ba7-00002.css
-rw-r--r-- 1  99  99 5876 Feb 18 05:37 style-cc2f96c9-00011.css

web2 correct username user/group permissions

ls -alh /home/username/public_html/forums/scripts/site_css
total 48K
drwxrwxrwx 2 root root 4.0K Feb 22 02:37 ./
drwxr-xr-x 3 username username 4.0K Dec 2 14:51 ../
-rw-r--r-- 1 username username 1 Nov 30 2006 index.html
-rw-r--r-- 1 username username 5.8K Feb 22 02:37 style-057c3df0-00011.css
-rw-r--r-- 1 username username 5.8K Feb 22 02:37 style-95001864-00002.css
-rw-r--r-- 1 username username 5.8K Feb 18 05:37 style-b1879ba7-00002.css
-rw-r--r-- 1 username username 5.8K Feb 18 05:37 style-cc2f96c9-00011.css

web2 numeric ids

ls -n /home/username/public_html/forums/scripts/site_css
total 48
drwxrwxrwx 2 503 500 4096 Feb 22 02:37 ./
drwxr-xr-x 3 503 500 4096 Dec  2 14:51 ../
-rw-r--r-- 1 503 500    1 Nov 30  2006 index.html
-rw-r--r-- 1 503 500 5876 Feb 22 02:37 style-057c3df0-00011.css
-rw-r--r-- 1 503 500 5877 Feb 22 02:37 style-95001864-00002.css
-rw-r--r-- 1 503 500 5877 Feb 18 05:37 style-b1879ba7-00002.css
-rw-r--r-- 1 503 500 5876 Feb 18 05:37 style-cc2f96c9-00011.css

I checked db1 /nfsroot/site_css and user/group ownership was incorrect for newer files dated feb22 owned by root and not username ?

on db1 originally incorrect root assigned user/group for new feb22 dated files

ls -alh /nfsroot/site_css
total 44K
drwxrwxrwx  2 root   root 4.0K Feb 22 02:37 .
drwxr-xr-x 17 root   root 4.0K Feb 17 12:06 ..
-rw-r--r--  1 root   root    1 Nov 30  2006 index.html
-rw-r--r--  1 root   root 5.8K Feb 22 02:37 style-057c3df0-00011.css
-rw-r--r--  1 root   root 5.8K Feb 22 02:37 style-95001864-00002.css
-rw-------  1 username nfs  5.8K Feb 18 05:37 style-b1879ba7-00002.css
-rw-------  1 username nfs  5.8K Feb 18 05:37 style-cc2f96c9-00011.css

Then I chmod them all on db1 and chown to set to right ownership on db1 so it looks like below

on db1 once corrected the newer feb22 dated files

ls -alh /nfsroot/site_css
total 44K
drwxrwxrwx  2 root   root   4.0K Feb 22 02:37 .
drwxr-xr-x 17 root   root   4.0K Feb 17 12:06 ..
-rw-r--r--  1 username username    1 Nov 30  2006 index.html
-rw-r--r--  1 username username 5.8K Feb 22 02:37 style-057c3df0-00011.css
-rw-r--r--  1 username username 5.8K Feb 22 02:37 style-95001864-00002.css
-rw-r--r--  1 username username 5.8K Feb 18 05:37 style-b1879ba7-00002.css
-rw-r--r--  1 username username 5.8K Feb 18 05:37 style-cc2f96c9-00011.css

but still web1 shows owned by nobody ? while web2 shows correct permissions ?

web1 still with incorrect user/group of nobody not matching what web2 and db1 are set to ?

ls -alh /home/username/public_html/forums/scripts/site_css
total 48K
drwxrwxrwx 2 nobody nobody 4.0K Feb 22 02:37 ./
drwxr-xr-x 3 username username 4.0K Feb 22 02:43 ../
-rw-r--r-- 1 nobody nobody    1 Nov 30  2006 index.html
-rw-r--r-- 1 nobody nobody 5.8K Feb 22 02:37 style-057c3df0-00011.css
-rw-r--r-- 1 nobody nobody 5.8K Feb 22 02:37 style-95001864-00002.css
-rw-r--r-- 1 nobody nobody 5.8K Feb 18 05:37 style-b1879ba7-00002.css
-rw-r--r-- 1 nobody nobody 5.8K Feb 18 05:37 style-cc2f96c9-00011.css

Just so confusing so any help is very very much appreciated!

thanks

Best Answer

It's confusing to try to understand what your problem is, you don't make it clear if you're checking a file on web1 on web1, or db1 on web1, or whatever. Please give a good description of what's you're actually seeing, without confusing the issue with copying and chmoding. Something simple like I create a file on db1, with permissions x:y and on web1 I see permissions a:b and on web2 I see permissions c:d.

First thing, using NFS, any file which is owned by root will usually be shared so that it's owned by nobody. This means that if you have root on the client machine, you effectively don't have root on the server. I think that explains some of what you're seeing.

Secondly, if you are running NFS, it's vital that the userid->username mappings are identical on all the servers. Unix filesystems only store a numeric id for userid & groupid, which are then mapped to usernames by programs like ls. Are you sure that they are all in sync? It could be that you've got a mismatch.

Finally, tar p is an option for extracting, not creating tars. It's ignored when creating tars, and even when it's used, it's not going to set the ownership to what they originally were. -p basically means, ignore the umask. Tar will create files owned by you only, unless you're root.