I am trying to run commands as sudo over SSH, without success:

ssh -t -p 2222 name@server /usr/bin/sudo << EOF
  chmod u-r /xy 
  chmod +x /xy
  sleep 5
  ps aux | grep xy
  sleep 5

This is not working. Without -t and /usr/bin/sudo:

sudo: no tty present and no askpass program specified

Single line command is working:

ssh -p 13001 -t name@server 'sudo /xy'

This should work:

ssh -t -p 2222 name@server "/usr/bin/sudo bash -c 'chmod u-r /xy; chmod +x /xy; ...'"
  • +1: ssh -t name@server "sudo command here" worked for me – Robbie Averill Nov 13 '14 at 2:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.