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.

1 Answer 1


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

scp -S "script.sh" /local/file [email protected]:/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 [email protected] /local/file userB@localhost:/remote/file 

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

scp -o [email protected] /local/file userB@localhost:/remote/file 

There are other options like ProxyCommand or port forwarding, which you can use on even older versions of OpenSSH. These are covered in Does OpenSSH support multihop login?.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .