I could get this to work on my box, but I'm not sure if sudoers
option requiretty
would break it.
On machine B create program that sudo
will use to ask for passwords.
e.g. /home/myname/askpass.sh
, chmod
it +x
#!/bin/bash
echo "my_password"
On machine A create connect script that will establish the ssh connection for the scp
and inject sudo
+ related commands into remote command.
e.g. call it ./fakessh.sh
, chmod
it +x
#!/bin/bash
oldargs=( $@ )
newargs=( )
while : ; do
[ "${oldargs[0]}" == "scp" ] && break
newargs+=( "${oldargs[0]}" )
oldargs=( "${oldargs[@]:1}" )
done
newargs+=( 'export SUDO_ASKPASS=/home/myname/askpass.sh' \; exec sudo -A -- "${oldargs[@]}" )
exec ssh "${newargs[@]}"
Note that the script above references /home/myname/askpass.sh
, update path as required.
Now run scp
almost normally:
scp -S ./fakessh.sh user@hostname:/etc/shadow ./
This does work for me. YMMV.
I can think of other hacks if you can run something like ncat
or socat
with sudo
, and point scp
at the custom listening port, but that's getting silly from security point.
scp
. – Jakuje Jul 18 '16 at 12:02sudo
for that. It can work also non-interactive, without password or authenticate you using different means (pam_ssh_agent_auth
). – Jakuje Jul 18 '16 at 12:05expect
script. – Jakuje Jul 18 '16 at 13:31