1

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?

Shashank Singh
  • 647
  • 1
  • 5
  • 22

2 Answers2

5

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.

Turn
  • 6,656
  • 32
  • 41
1

Try ssh -t which would allocate a tty for you.

  • Using `sshpass -p "password" ssh -t -o StrictHostKeyChecking=no user@192.168.0.2 " ls /root/path/of/file"` prompts `[sudo] password for user:`. I want that the password should be added automatically. – Shashank Singh Jan 16 '18 at 07:37
  • 1
    Then you need to 1) confiugre sudo for password-less usage or 2) use tools like [tag:expect]. –  Jan 16 '18 at 09:48