2

Ok, so I already know how to copy a file in my machine to another one, and when I do it, (I'm trying to copy it to a sudo protected directory) it says permission denied. I do not know where to put the sudo so it isn't in my machine but it doesn't get in the way of the directory. Here's what I normally type:

scp /Users/username/Documents/folder/folder/script.py pi@192.168.x.xx:/usr/local/bin

1 Answer 1

4

You could use sudo dd like:

ssh user@host 'sudo dd of="/remote/path/to/file"' < "/local/path/to/file"

or use rsync:

rsync -av -e ssh --rsync-path="sudo rsync" "/local/path/to/file" user@host:"/remote/path/to/"
2
  • 2
    I don't know rsync but I can tell something about the first command: (1) /remote/path/to/file is quoted locally but not in the remote shell; some paths may be misinterpreted, possibly badly. (2) tee will unnecessarily print its input, ultimately to the local terminal; in general the input file may be big and/or binary. (3) sudo may ask for password or require tty anyway; see this question of mine for some insight. My point is the first command will work in fortunate circumstances, but in less fortunate it may wreak havoc. Dec 18, 2021 at 15:32
  • 2
    @KamilMaciorowski Thanks for the headsup! I updated the answer.
    – pLumo
    Dec 18, 2021 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.