Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an interactive shell script, that at one place needs to ssh to another machine (Ubuntu based) and execute something as root (the user should enter his password, but the remote command should run like noted in the script):

# ...
ssh remote-machine 'sudo ls'
# ...

However, I always get this error message back:

sudo: no tty present and no askpass program specified

OK, that's quite clear. But how can I circumvent this? Something like this should happen:

$ ssh remote-machine 'sudo ls /'
[sudo] password for user1:

share|improve this question

2 Answers 2

sudo su

Then type your password...

ls <--- this will be as root

You'll be working as root, so be bloody careful!

When finished:

share|improve this answer
Thanks for the answer! The problem is, that that doesn't help me in my setup, where the remote command is specified in the local script. However, I found a solution (see below). –  Boldewyn Mar 9 '10 at 12:11
up vote 40 down vote accepted

The wondrous ssh has a cure for everything. The point is to add the -t flag to force ssh to allocate a pseudo-tty:

ssh -t remote-server 'sudo ls'
share|improve this answer
PTYs can mess things up with scripts, however. ls output will contain \r\n endings for example. –  Tobu Jun 14 '10 at 18:58
The easy way around that is to force ls into non-terminal mode. ls | cat will do - it'll see that stdout is a pipe. In this specific question, that's not relevant, as it's apparently intended to be run interactively from a terminal - so you probably want the columns and colours and whatnot. –  Gabe Apr 26 '13 at 8:31

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.