Search code examples
rubysshsudotty

How to use sudo programmatically via a pipe?


I am trying to write a program to perform remote administration of a system. To this end, I issue SSH commands and provide input programmatically via a pipe. I also capture their output.

Some of the commands require elevation, so I need to issue commands such as ssh user@host "sudo apt-get install blah".

The problem is, sudo refuses point-blank to accept a password via the terminal unless it finds a real terminal on its stdin. Is there some way I can fool sudo into allowing this?


Solution

  • found here: https://askubuntu.com/questions/470383/how-to-avoid-prompt-password-for-sudo

    echo 'password' | sudo -S command
    

    -S accepts password from stdin