46
18
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
1PTYs can mess things up with scripts, however.
ls
output will contain \r\n endings for example. – Tobu – 2010-06-14T18:58:18.4131The 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 – 2013-04-26T08:31:40.270