up vote 9 down vote favorite
5
share [g+] share [fb]

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:

/bin
/etc
/var
link|improve this question

feedback

2 Answers

up vote 8 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'
link|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
feedback
sudo su

Then type your password...

ls <--- this will be as root

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

When finished:

 exit
link|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
feedback

Your Answer

 
or
required, but never shown

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