Fedora, ssh and sudo

Posted by Ricky Robinson on Server Fault See other posts from Server Fault or by Ricky Robinson
Published on 2014-05-27T09:18:23Z Indexed on 2014/06/03 9:27 UTC
Read the original article Hit count: 304

Filed under:
|
|
|
|

I have to run a script remotely on several Fedora machines through ssh. Since the script requires root priviliges, I do:

$ ssh [email protected]_host "sudo touch test_sudo" #just a simple example
sudo: no tty present and no askpass program specified

The remote machines are configured in such a way that the password for sudo is never asked for. For the above error, the most common fix is to allocate a pseudo-terminal with the -t option in ssh:

$ ssh -t [email protected]_host "sudo touch test_sudo"
sudo: no tty present and no askpass program specified

Let's try to force this allocation with -t -t:

$ ssh -t -t [email protected]_host "sudo touch test_sudo"
sudo: no tty present and no askpass program specified

Nope, it doesn't work.

In /etc/sudoers of course I have this line:

#Defaults    requiretty

... but I can't manually change it on tens of remote machines.

Am I missing something here? Is there an easy fix?

EDIT:

  • Here is the sudoers file of a host where ssh [email protected] "sudo stat ." works.
  • Here is the sudoers file of a host where it doesn't work.

EDIT 2: Running tty on a host where it works:

$ ssh  [email protected]_ok tty
not a tty

$ ssh -t [email protected]_ok tty
/dev/pts/12
Connection to host_ok closed.

$ ssh -t -t [email protected]_ok tty
/dev/pts/12
Connection to host_ok closed.

Now on a host where it doesn't work:

$ ssh [email protected]_ko tty
not a tty

$ ssh -t [email protected]_ko tty
not a tty
Connection to host_ko closed.

$ ssh -t -t [email protected]_ko tty
not a tty
Connection to host_ko closed.

© Server Fault or respective owner

Related posts about ssh

Related posts about fedora