I am trying to copy dirs and files under the root on the remote host, using non-root user, which one actually doesn`t have access to this folders. So I need something like sudo while copying.
Sample command:
scp user@<host>:<path_to_folder_under_the_root> .
I cannot use root@ cause I have not the root keys local. Is there any possible ways to do this?
CodePudding user response:
Assuming that you do have sudo access on the remote host, instead of using scp you can use ssh and tar:
ssh user@<host> sudo tar -C <path_to_folder_under_the_root> -cf . | tar -xf-
CodePudding user response:
The solution that works for me is rsync --rsync-path="sudo rsync".
@larsks`s solution might also be suitable for this case.
