I have a file on server A (which is behind a NAT so not directly addressable). The file needs to be copied to server B in a directory restricted to root. I have an account on server B with sudo privileges. What is the syntax for the scp command?
Answer
First, you need to copy the file to a place where you have write access without sudo,
scp yourfile serverb:
Then move the file using sudo
ssh serverb sudo mv yourfile /path/to/the/destination
If you do not have a writable place, make a temporary dir with write permission for your user.
ssh serverb sudo mkdir tempdir && sudo chmod 777 tempdir
scp yourfile serverb:tempdir
ssh serverb mv tempdir/yourfile /path/to/the/destination
Attribution
Source : Link , Question Author : Neil , Answer Author : Johan