Asked 9 years, 10 months ago. Active 3 years, 10 months ago. Viewed 97k times. SCP does not seem to preserve ownership stamps even if used with -p option. Improve this question. Add a comment. Active Oldest Votes. Try to use rsync, it has a lot more benefits besides keeping ownership, permissions and incremental copies: rsync -av source Improve this answer. That is correct. See the man page: -p Preserves modification times, access times, and modes from the original file.
Nex7 Nex7 1, 11 11 silver badges 13 13 bronze badges. Sign up or log in Sign up using Google. 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. If you want to copy a dir. No unix, no fun. Valued Contributor. One thing to consider is the method in which scp utilizes preserving permissions and ownership.
So, if you "scp -p" a file owned by user MickyMouse with a uid of to another server, that file on the destination server will be owned by uid However, uid on the destination server may very well map to DonaldDuck instead of MickeyMouse.
Active 3 months ago. Viewed k times. Do you know how i could deal with this? Improve this question. Jorge Castro Dimitris Sapikas Dimitris Sapikas 2, 2 2 gold badges 12 12 silver badges 9 9 bronze badges.
This seems more like a question for your virtual server provider, or for the putty or winscp developers. Why is this closed? This is a perfectly valid question about copying files with scp - every web developer is familiar with this situation — Sergey. Copying protected files between servers in one line? I have a similar problem. And it says that there is a permission problem.
Any idea why adding to user to www-data still don't allow user to copy a file to folder which is owned by www-data group? Add a comment. Active Oldest Votes. Improve this answer. Brandon Bertelsen 2, 2 2 gold badges 31 31 silver badges 47 47 bronze badges.
Sergey Sergey 42k 11 11 gold badges silver badges bronze badges. It's ludicrous you can't setup a root account to use scp for root owned files. Who owns my computer me or Canonical? It's just as bad as Android and Google from that respect.
WinEunuuchs2Unix: indeed you can to set up your machines so you can SSH in as root, all it takes is a small change in a config. Once you do that you can scp files as root as much as you want. Show 2 more comments. Anderson Lira Anderson Lira 1, 1 1 gold badge 6 6 silver badges 3 3 bronze badges.
This answer is underrated. It's simple, clean, reads or writes a root file with a single atomic operation, and requires nothing that's not already guaranteed to be there if you're using scp. Main drawback is that it does not copy permissions. If you want that, the tar solution is better. Beautifully done. This is exactly what I was looking for both up and down. Thank you — Jeremy. Deserves to be the top answer, for sure. Can this be done for a directory instead of a file as well?
Otherwise it will error with sudo: no tty present and no askpass program specified. And tee -a? The question is about copying, not about appending and at the same time echoing back to stdout. Show 6 more comments. IBBoard 2 2 silver badges 8 8 bronze badges.
This is the best way to do it. I can't get this method to work successfully. As written I get sudo: sorry, you must have a tty to run sudo. I can't see this working without passwordless sudo. IBBoard : try the solution here using ssh -t: ssh -t dimitris myserver.
AlexanderBird While that works in many cases, I'm not sure it works here because we're trying to pipe a tarball over the SSH connection. See serverfault. This is what finally worked for me. You don't have permissions to a remote file that you want to copy to local, do a sudo tar , archive it, change permissions using chmod and chown , and then copy it to local. Especially if it's a directory. Show 3 more comments. You can also use ansible to accomplish this. It is the way to use ansible without needing an inventory file.
Copying a directory is supported by the copy module, but not by the fetch module.
0コメント