2

I have a script running on a remote host through ssh, processing stdin from the host.

That is the script does something like this (to simplify):

cat $TARBALL | ssh $REMOTE 'tar -x -C -f - && reboot'

This work fine if I use root as the ssh user, but if I don't have root access on the REMOTE, I want to execute the command with sudo instead, eg:

cat $TARBALL | ssh $REMOTE 'sudo tar -x -C -f - && sudo reboot'

I would want the user to be asked the password interactively here, but sudo can't get the password in that situation.

How can I somehow instruct sudo to ask for the password on the local terminal? Seems like the -A option could enable this, but I can't figure what askpass program I might need in this case.

1
  • ssh $HOST 'sudo -S ls | grep my_file'
    – Larytet
    Apr 1, 2022 at 6:45

1 Answer 1

-1

When you have to deal with passwords prompts on standart input, the recommanded Unix way is to use the expect(1) tool which was made specially for that purpose.

1
  • 1
    How does expect help here? sudo won't have a prompt on stdout and stdin is used to provide other data
    – Droopycom
    May 8, 2021 at 2:09

You must log in to answer this question.

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