1

This is my script:

#!/bin/sh

echo "I'm local"

ssh -t -t remote.server << 'EOF'
    sudo echo "I'm remote and sudo"
    echo "I'm remote but not sudo"
    exit
EOF

This simply doesn't work, maybe because the line echo "I'm not sudo" is supplied as a password.

How can I make it work, without:

  • feeding the password directly to the script
  • enabling password-less sudo, or
  • making everything sudo?

Or, perhaps my approach is completely wrong or unusual for this purpose?

akai
  • 113
  • 5

1 Answers1

1

In my opinion the only way is to split into two separate ssh commands:

#!/bin/sh

echo "I'm local"

ssh -t remote.server "sudo echo \"I'm remote and sudo\""
ssh -t remote.server "echo \"I'm remote but not sudo\""

The redirection which you use, will always redirect whole block to the command and will not wait for any subcommand success (or fail).

dave
  • 303
  • 3
  • 16