Changing user while scp

scpusers

I need to copy file between Linux machines. The problem that the user I use to login (myuser), is different from the user that can access the file.

If I just ssh to the machine, I can switch the user using sudo su someuser, can I do it somehow while scp?

While using WinSCP I managed to do it, by configuring the SCP/Shell, so I believe there must be a similar way to do it via pure shell.

Best Answer

Assuming that the user you CAN ssh to doesn't need a password to sudo su into the target user, you can try this:

dd if=myfile | ssh some.host "sudo -u targetuser dd of=myfile" 

... Mind, I'm still unconvinced that simply configuring targetuser to only allow scp/sftp/rsync over SSH and using a RSA keypair for authentication isn't a much better option.

Related Question