3

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
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
Nick M
  • 35

1 Answers1

5

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/"
pLumo
  • 22,565
  • 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. – Kamil Maciorowski Dec 18 '21 at 15:32
  • 2
    @KamilMaciorowski Thanks for the headsup! I updated the answer. – pLumo Dec 18 '21 at 18:47