Search code examples
linuxsshsudo

No remote commands executed when ssh runs as sudo


The following command gives the expected result (file is created):

sshpass -p pas ssh root@host 'touch foo'

But the following one does nothing on the remote host:

sudo sshpass -p pas ssh root@host 'touch foo'

The only difference here is just sudo mode.

What is the reason here? And how this can be solved?


Solution

  • The problem is more visible when running ssh -v.

    With sudo communication interrupts after detecting the server host key.

    To solve the problem ssh needs to run with the following argument -o "StrictHostKeyChecking no".