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
Best Answer
You need to have a terminal available to run
sudo
so that it can prompt you for the password. If you pass a command tossh
, 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, runssh
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 withNOPASSWD
, if therequiretty
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
forotheruser@computertwo.com
).