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 user@192.168.0.2 " 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 user@192.168.0.2 "sudo ls /root/path/of/file"
Output :
sudo: no tty present and no askpass program specified
What should I do?
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.