0

I'm running a bash script to execute a command on a remote host. Here is the command:

ssh ppuser@10.101.5.91 "sudo mv /tmp/$2.tar.gz $1"

$1 and $2 are command line arguments. But while executing I'm getting this error : no tty present and no askpass program specified.

Hope you will help me, any help would be greatly appreciated. Thank You.

duplode
  • 33,731
  • 7
  • 79
  • 150
Madura Dissanayake
  • 8,309
  • 5
  • 25
  • 34
  • It seems that you need to set up ssh key authentication http://stackoverflow.com/questions/7260/how-do-i-setup-public-key-authentication – user3132194 Apr 22 '14 at 06:47
  • possible duplicate of [How to fix 'sudo: no tty present and no askpass program specified' error?](http://stackoverflow.com/questions/21659637/how-to-fix-sudo-no-tty-present-and-no-askpass-program-specified-error) – Kenster Sep 05 '15 at 21:37

3 Answers3

2

Somewhere in your sudoers file you have following

Defaults requiretty

Just comment this line - remove it. Or

Defaults !requiretty

For specific program name you can also attempt following:

Defaults </path to program> requiretty

change it to

Defaults </path to program> ! requiretty

Specific to user you can add

Defaults:username !requiretty

Adding What already have been specified in comment, For the same you will have to

user-name    ALL=(ALL)  NOPASSWD: ALL

Its for passwordless sudo

PradyJord
  • 2,136
  • 12
  • 19
  • Hi, Jord, Thanks for the help, I checked on the /etc/sudores file, but the "Defaults requiretty" already have been removed, but still getting the same error, any other thing to do? , hope u eill help, Thank You. – Madura Dissanayake Apr 22 '14 at 08:17
  • Have you tried after removing every entry for tty `Defaults !requiretty` basically two things are required to run cmd on remote the way you are doing 1) requiretty removed 2) and NOPASSWD sudo for user with which you are connecting remotely. – PradyJord Apr 22 '14 at 09:24
  • Hello Jord, Thanks for the help, after adding NOPASSWD after the sudo on sudores file, it worked. I'll edit ur answer thank you..so..much... :) – Madura Dissanayake Apr 22 '14 at 10:29
  • @user3440631 how about accepting it as a soulution thn :) – PradyJord Apr 22 '14 at 10:32
1

Looks like you are invoking sudo, and it is not working because it doesn't have a tty bound. add

"Defaults visiblepw" 

in sudoers file enables sudo even if a console doesn't allocate a tty. Use visudo on the remote machine to add this and see if this helps.

nohup
  • 3,105
  • 3
  • 27
  • 52
-1

Try this command

sshpasss -p password ssh ppuser@10.101.5.91 "sudo mv /tmp/$2.tar.gz $1"
Rahul R Dhobi
  • 5,668
  • 1
  • 29
  • 38
  • Hello @Rahul, I have already added public key to the remotehost(10.101.5.91) so i need to execute the command without the password. So hope u will help, thank You.... :) – Madura Dissanayake Apr 22 '14 at 06:54
  • The OP is successfully authenticating through ssh. The error is coming from sudo. You also misspelled "sshpass". – Kenster Sep 05 '15 at 21:38