set environment variable SSH_ASKPASS or askpass in sudoers, resp

后端 未结 6 2065
孤城傲影
孤城傲影 2021-02-07 07:12

I\'m trying to login to a ssh server and to execute something like:

ssh user@domain.com \'sudo echo \"foobar\"\'
         


        
6条回答
  •  遥遥无期
    2021-02-07 07:59

    Another way is to run sudo -S in order to "Write the prompt to the standard error and read the password from the standard input instead of using the terminal device" (according to man) together with cat:

    cat | ssh user@domain.com 'sudo -S echo "foobar"'
    

    Just input the password when being prompted to.

    One advantage is that you can redirect the output of the remote command to a file without "[sudo] password for …" in it:

    cat | ssh user@domain.com 'sudo -S tar c --one-file-system /' > backup.tar
    

提交回复
热议问题