cancel
Showing results for 
Search instead for 
Did you mean: 

SCP Copy problem

 
VICBUR1507
Frequent Advisor

SCP Copy problem

Hi mates,
I have a problem making a copy from a Linux server to an HP-UX server, the copy I'm doing with the scp command with the-r and -p options, but then generated the copy and review on the HP-UX server the copy is made perfectly even with the same permissions, but the owner permissions of the folders and files change the ownership to root.

Anybody can help Me??

Thanks guys
7 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: SCP Copy problem

Hi:

This is standard behavior. You could create an empty file on the receiving server and establish its appropriate ownership. Then, perform your 'scp -p' transfer. Now the permissions, timestamps and ownership will be preserved.

Regards!

...JRF...
Tingli
Esteemed Contributor

Re: SCP Copy problem

That is the way it is, because you do your scp in root account.

You can login as the file owner to do the scp and it keeps the original ownership.
Bill Hassell
Honored Contributor

Re: SCP Copy problem

When you use scp, the full specification of the destination filename is user@host:/path. If you leave off the user then the remote file will be owned by the user sending the file. If you login as root, then send the file to the remote system like this:

scp -rp /tmp/mydir billh@system2:/tmp

Then the directory (and files) will be owned by billh. For a password free copy, you'll have to setup the public key for the user billh.


Bill Hassell, sysadmin
Steven Schweda
Honored Contributor

Re: SCP Copy problem

> [...] a Linux server [...]

Not a very complete description of the OS
or the SSH software on this system.

> [...] an HP-UX server [...]

Not a very complete description of the OS
or the SSH software on this system.

Around here:

dyi # uname -a
HP-UX dyi B.11.31 U ia64 4235313755 unlimited-user license

dyi # ssh -V
OpenSSH_5.2p1+sftpfilecontrol-v1.3-hpn13v5, OpenSSL 0.9.8k 25 Mar 2009
HP-UX Secure Shell-A.05.20.015, HP-UX Secure Shell version


dyi # man scp
[...]
-p Preserves modification times, access times, and modes from the
original file.
[...]

Nothing there about owner/group. And not
without good reason.

Preserving ownership between different
systems can be difficult, especially when a
user exists on one system but not on the
other. It can also cause problems, when, for
example, a particular UID number translates
to different users on the different systems.

If you _really_ do wish to preserve the
UID/GID values, then you may be able to do
better using "tar". It should be possible to
string together a "tar" pipeline using ssh
(not quite scp, but close) for the remote
half.


> [...] with the-r and -p options [...]

> You could create an empty file [...]

Uh, _many_ empty files? Even if it works, it
sounds impractical.

> You can login as the file owner to do the
> scp and it keeps the original ownership.

Because all the files are certain to have the
same owner (and group)?


Providing a clear description of the problem
to be solved can reduce (but probably not
eliminate) the suggestions which don't really
apply to the actual situation.
AVV
Super Advisor

Re: SCP Copy problem

But here we use switches as -p -r to copy with same permission and subdirectories. Why do we need to copy as the user who have the onwership of the files/dir. Can someone explain me this well
Steven Schweda
Honored Contributor

Re: SCP Copy problem

> But here we use switches as -p -r to copy
> with same permission and subdirectories.

Ok.

> Why do we need to copy as the user who have
> the onwership of the files/dir.

You don't need to, if you don't care who owns
the files at the destination.

> [...] Can someone explain me this well

Again?

> Nothing there about owner/group. [...]
Victor Fridyev
Honored Contributor

Re: SCP Copy problem

Try to use tar over ssh like that:

cd source_dir; tar cf - dirs_and_files | ssh root@target "cd destin_dir; tar xf - "

Tar stores ownership and permissions if executed as root.
Or you can use rsync, which is perfect for the purpose.

HTH
Entities are not to be multiplied beyond necessity - RTFM