16

I keep getting this error and have tried several ways discussed online to fix this and none are working for me. I have setup SSH keys so when I run 'ssh newton@host.com' it automatically logs me in, I have also set this user in visudo to be 'newton ALL=(ALL:ALL) ALL' I then also tried to add 'newton ALL=NOPASSWD: /var/www/script.sh'

Unfortunately, every time I run ssh newton@host.com 'sudo /var/www/script.sh' from Cygwin I get back. I have also tried to add -t -t but then it prompts me for the password.

total size is 21209180  speedup is 314.69
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • This is not specific to Cygwin; I see the same problem using ssh example.com sudo echo hello from one Linux system to another. I've updated your title accordingly. I've also flagged your question for migration to the Unix site. – Keith Thompson Sep 18 '12 at 21:33

8 Answers8

12

You need to have a terminal available to run sudo so that it can prompt you for the password. If you pass a command to ssh, it assumes that the command doesn't need a terminal and doesn't create one, unless you pass -t. See SSH inside SSH fails with "stdin: is not a tty" for a more detailed explanation.

If you aren't able to enter the password even with -t, it's possible that your problem is due to Windows. The Windows console does not completely emulate a unix terminal; there may be some difficulty for Cygwin applications to properly emulate a terminal in these circumstances (I'm not sure about that, note). If that's the problem, run ssh inside a terminal emulator such as Console2 or Mintty (included in the Cygwin distribution) — see Best way to use a shell with Cygwin in Windows 7.

If you expected the SSH passphrase to replace your password for authentication to sudo, that's not going to happen. Sudo requires a password (unless you add the NOPASSWD tag in the sudoers file). Note that you still need to have a terminal, even with NOPASSWD, if the requiretty option is set in the sudoers file.

If you want passwordless login up to the root account (which is generally not a good idea from a security perspective), use SSH to reach the root account, preferably in two hops. See SSH inside SSH fails with "stdin: is not a tty" (with root@host.com for otheruser@computertwo.com).

4

Let's you want to enable no password for nodejs command/binary.

Modify visudo

sudo visudo

With following line to enable no password for a command. Pass is multiple commands with commas and space after each commands.

<user name> ALL = NOPASSWD: /usr/local/bin/node

ex. sunthara ALL = NOPASSWD: /usr/local/bin/node

enter image description here

1

Edit ssh-server configuration file and append at the bottom:

root# vim /etc/ssh/sshd_config

Match User newton
    PermitTTY yes
ILMostro_7
  • 3,309
  • Does not work: service sshd restart => /etc/ssh/sshd_config: line 91: Bad configuration option: User – kiltek Apr 26 '17 at 07:58
  • Might need to be changed to Match User newton – ILMostro_7 Apr 26 '17 at 08:38
  • 1
    No it means that you cant write User into your sshd file, because that configuration option does not exists. (at least thats the case on my system Ubuntu 16.04) – kiltek Apr 26 '17 at 09:27
  • From the man-pages: "MatchIntroduces a conditional block. If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file.

    The arguments to Match are one or more criteria-pattern pairs. The available criteria are User, Group, Host, and Address. The match patterns may consist of single entries or comma-separated lists and may use the wildcard and negation operators described in the PATTERNSsection of ssh_config(5)."

    – ILMostro_7 Apr 26 '17 at 10:41
  • I dont see a Match block in your answer... – kiltek Apr 26 '17 at 11:10
  • Ok you corrected it, well done. – kiltek Apr 26 '17 at 12:09
0

commenting the below parameters in /etc/sudoers file helped me.

# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
#         You have to run "ssh -t hostname sudo <cmd>".
#
Defaults    requiretty

#
# Refuse to run if unable to disable echo on the tty. This setting should also be
# changed in order to be able to use sudo without a tty. See requiretty above.
#
Defaults   !visiblepw

---> comment out the parameters as follows

#Defaults    requiretty
#Defaults   !visiblepw
cxw
  • 1,246
0

I faced this error when I made a mistake in /etc/sudoers. Instead of specifying multiple commands like this:

NOPASSWD= /bin/x, /bin/y

I saved as:

NOPASSWD= /bin/x /bin/y

i.e. without the comma. Now I get the no tty present message when I try

ssh host 'sudo x'
0

Pour les personnes qui ont le message d'erreur:

No TTY present and no askpass program specified

quand ils lancent un script depuis le client vers une machine distante, la bonne syntaxe est :

ssh -t userdistant@IPdest ''bash -s' < '/chemin/de/mon/script''

Faites bien attention à mettre l'ensemble du bloc après IPdest entre quote simple. En plus cela permet une interactivité avec le script directement depuis la source (par exemple entrer mot de passe, répondre à une requête du script...)

Archemar
  • 31,554
  • 1
    Bonjour, 1) j'ai formaté pour mettre en évidence le code, 2) normalement la langue officielle ici est l'anglais (même si il y a des francophones), 3) tu es sûre de la syntaxe avec les quotes ? – Archemar Apr 19 '21 at 15:14
0

Add this entry in /etc/sudoers:

  Defaults:newton !requiretty 
tonioc
  • 2,069
0

Don't know if it is related but when I had '...NOPASSWD: /xyz/script.shl' in the sudoers file, I got that error message until I included the #!/bin/shellname line at the top of the /xyz/script.shl file.

Anthon
  • 79,293
LeeH
  • 1