I was wondering if it's an option to scp as different user(not the one who connects to remote server). For example, if user A has kerberos ticket to server X and user A has sudo access to user B. Is it possible to scp files to remote server X as user B? Any help is appreciated.


It is theoretically possible with use of the -S switch with a construct like:

scp -S "script.sh" /local/file userA@example.com:/remote/file 

Where the script.sh executes ssh will all arguments it gets, except for that it prefixes scp with sudo. And it would work only, if you make sure that sudo does not prompt for a password. What is actually part of my current outstanding question on Super User:
Allowing automatic command execution as root on Linux using SSH.

Another option, if you have local host connections allowed for the the "user B" on the remote server, you can use -J (jump) switch (supported since OpenSSH 8.0) like:

scp -J userA@example.com /local/file userB@localhost:/remote/file 

With older versions (but at least 7.3) you can use ProxyJump directive:

scp -o ProxyJump=userA@example.com /local/file userB@localhost:/remote/file 

On even older version, you can use the -S switch.
For details see also How can I download a file from a host I can only SSH to through another host?

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.