Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'
share|improve this question… might come in handy, though you already mentioned -t – Hennes Feb 16 '13 at 20:23
up vote 9 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
+1: ssh -t name@server "sudo command here" worked for me – Robbie Averill Nov 13 '14 at 2:00

Your Answer


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.