Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
  /xy
  sleep 5
  ps aux | grep xy
  sleep 5
  exit
EOF

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'
share|improve this question
    
unix.stackexchange.com/questions/48554/… might come in handy, though you already mentioned -t –  Hennes Feb 16 '13 at 20:23

1 Answer 1

up vote 7 down vote accepted

This should work:

ssh -t -p 2222 name@server "/usr/bin/sudo bash -c 'chmod u-r /xy; chmod +x /xy; ...'"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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