Solved

How do I copy files to a NFS mount directory and also preserve the group and user ownership of the files?

Posted on 2008-10-17
7
6,640 Views
Last Modified: 2013-12-21
Hi,

I am in the process of transferring files from a systems local directory to a NFS mount directory on that same system.  In the process of copying the files from the old directory to the NFS mount directory, I receive several messages of "cp: failed to preserve ownership for <file name> : Not owner" .  The previous user and group owners have now changed to nobody4 and nogroup in the NFS mount directory.  Please assist on the command that I should have used to prevent this from happening?  Is there something that I should configure on the NAS system (NetApp)?  If there so, please provide a solution.  I really appreciate your help.
0
Comment
Question by:gsalcedo
7 Comments
 
LVL 22

Expert Comment

by:blu
ID: 22743109
You need to run the command as root with the "-p" option to cp. In addition, you need to have root access to the NFS mount, which is doesn't sound like you have. In that case, you need to run the cp command from the account of the user that owns those files. You can use the su command to become the user and then run the cp command.  When the root user on a system is not set as a trusted root account, you usually find that the files that root creates on the NFS volume end up owned as "nobody"
0
 

Author Comment

by:gsalcedo
ID: 22743522
Hi blu,

When I copy the files, I did it as root.  The command that I used was cp -pr <file name> <NFS mount directory>.  Even as root, I still receive the "cp: failed to preserve ownership for <file name> : Not owner" errors.  Is there some options that I am supposed select on the NAS system's NFS export volume, such as Actual Path, Anonymous User ID, Root Access and more?
0
 
LVL 22

Expert Comment

by:blu
ID: 22743692
Correct. The key thing is the "root access". Without root access, the remote root user is treated as an ordinary user, namely the "nobody" user. That means that the attempts to change the owner of the file failed and the file owner was left as "nobody". If you set root access for the remote system, then the root user will be treated as root and not as nobody, and the attempts to chnage the ownership will succeed.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 6

Expert Comment

by:peter991
ID: 22765995
How does your /etc/dfs/dfstab look on the receiving node?
0
 

Author Comment

by:gsalcedo
ID: 22766362
Hi Everyone,

The problem was not the options that I indicated with the "cp" command, but the options that I selected on the NFS server (NetApp).  One of the options that I had to select was "Anonymous user."   After selecting that option and then running the same "cp" command with the "-pr" options, the copy of the files with the right ownership worked just fine.  Thank you very much for your advices.
0
 
LVL 22

Accepted Solution

by:
blu earned 500 total points
ID: 22766632
You apparently have set anonymous user to root. This is a common solution and has a similar effect as setting the root user as trusted. However, the security ramifications are huge. You should never set the anonymous user to 0 or root.  Consider what is happening:

The reason that root is not trusted by default is that this makes the access of the files on the server dependent on the trustworthiness of the client. Root has special privs, and the server relies on the client to specify the user of all operations. If the client is malicious, then it is trivial to access all files on the server as root, if the root user on the client is trusted by default.

So, the default is to set accesses by root on the client to be treated as if there are access by an anonymous users, usually nobody. Thus root on the client will only have the accesses that any user on the server would have, preventing root from accessing anything other than world readable files.

When you set anonymous user to 0, you are reversing the effect of the mapping. Root gets mapped to the anonymous user, and the anonymous user gets mapped back to root. So, this solved your problem, root gets root access on the server.

But consider, you have given root access to all clients, including untrusted ones. You have also now given root access to clients that have unauthenticated users. So, for some kind of clients that do not provide authentication (some PC clients, for instance), users using those clients will get root access to the servers, by *default*.

The correct mechanism is the one I described, namely to set the export options to trust the client the root access from individual clients, not to map the anonymous user to 0.
0
 
LVL 3

Expert Comment

by:Saranyakkali
ID: 22785588
1. Make your nfs mount as read write

share -F nfs -o rw,anon=0  /mount

mount it in local as mounttest

copy all files from mount1 to mounttest

cd /mount1; tar cvfp - . | (cd /mounttest; tar xvfp -)

that's all
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
replace column/record content in a *csv file based on a regular expression 6 72
Ping / Map Network Drive Issues 7 86
aws pricing 2 61
Problem to router 7 71
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question