Search code examples
shellsudosshpass

Error "sudo: no tty present and no askpass program specified" while using with sshpass


I want to write a script in which I need to get the content of a file from different machine 192.168.0.2 without enterging the password so I used sshpass with the following command :

sshpass -p "password" ssh -o StrictHostKeyChecking=no [email protected] " ls /root/path/of/file"

Output :

ls: cannot access '/root/path/of/file': Permission denied

I get it because I sidn't login as a root user. So I tried :

sshpass -p "password" ssh -o StrictHostKeyChecking=no [email protected] "sudo ls /root/path/of/file"

Output :

sudo: no tty present and no askpass program specified

What should I do?


Solution

  • As details by this answer on StackExchange, the /etc/sudoers file on the remote host is likely disallowing you from running sudo commands without a tty. It also has a number of detailed recommendations for working around the problem if you can't fix it.