Operating System - HP-UX
1821068 Members
2713 Online
109631 Solutions
New Discussion юеВ

scp to remote server, and keep the ownership and permission the same

 
Hanry Zhou
Super Advisor

scp to remote server, and keep the ownership and permission the same

If I run scp as root, and these files will be owned by root when they are copied over to the remote host.

I wanted to keep the same ownership as they were on local system.

I tried -p option, and it did not work either.

Any idea?
none
7 REPLIES 7
G. Vrijhoeven
Honored Contributor

Re: scp to remote server, and keep the ownership and permission the same

Hi,

i would use ssh to do a tar ( remote), copy that file and extract localy.

Regards,

Gideon
Jeroen Peereboom
Honored Contributor

Re: scp to remote server, and keep the ownership and permission the same

Try scp file remoteuser@remoteserver:/destfile.

Of course, ff you have files owned by different users this becomes awkward.

JP.
Steven E. Protter
Exalted Contributor

Re: scp to remote server, and keep the ownership and permission the same

Set up the user for password free scp

then as the user use scp -p

that will work.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Abdul Rahiman
Esteemed Contributor

Re: scp to remote server, and keep the ownership and permission the same

No, scp wo't kep the ownership even if copied with -p option. The reason why the file ownership is being changed to root is because the ownership of the file is determined by the user who is doing SSH authentication. As long as you are using root or a different user top copy, scp will change the ownership to that user(remote user).

Your solution would be,
1. Use the owner of the file to use copying and setup key based authentication for the user(it would be painful if you ant multiple users to use this).

2. If you want to copy a dir.structure, use the tar | ssh command as follows,
tar cpf - dir | (ssh remote_Server "cd remote_dir; tar xpf -")


HTH,
Abdul.
No unix, no fun
Michael Denney
Valued Contributor

Re: scp to remote server, and keep the ownership and permission the same

One thing to consider is the method in which scp utilizes preserving permissions and ownership. The preservation method of file ownership with scp is based on inode entries, not user names in /etc/passwd. So, if you "scp -p" a file owned by user MickyMouse with a uid of 100 to another server, that file on the destination server will be owned by uid 100. However, uid 100 on the destination server may very well map to DonaldDuck instead of MickeyMouse. Solution is to use something like NIS, or manual methods to keep all you uid/gid's in sync..

2 cents from the peanut gallery.
Hanry Zhou
Super Advisor

Re: scp to remote server, and keep the ownership and permission the same

Michael,

The user account and id number are consistency on both remote and local servers.
none
Uday_S_Ankolekar
Honored Contributor

Re: scp to remote server, and keep the ownership and permission the same

Either you will have to genearate ssh key for that perticualr user who owned the file or run chown command after every scp to modify owner informations.

-USA..
Good Luck..