When attempting to run a remote binary using sudo
on the remote box:
ssh remotehost "sudo ./binary"
I see this error:
sudo: no tty present and no askpass program specified
How can I work around this?
When attempting to run a remote binary using sudo
on the remote box:
ssh remotehost "sudo ./binary"
I see this error:
sudo: no tty present and no askpass program specified
How can I work around this?
A simple way is to specify
-t
:From the man page:
I cannot explain exactly why this works, and there may be a better way. I'd like to hear about it if so :)@psusi explains why this works in a comment below.
Question:
How can I work around this?
Alternate Answer
As an alternative, try:
sudo -S ./[yourExecutable]
This directs sudo to read the password from the standard input, stdin.
Scenarios where this Helps
In chroot environments, these other answers may not work correctly ... perhaps because:
For example: Manually installing / repairing linux or the bootloader, using a chroot environment, (such as Archlinux and arch-chroot).
It fails, because
sudo
is trying to prompt on root password and there is no pseudo-tty allocated.You've to either log-in as root or set-up the following rules in your
/etc/sudoers
(or:sudo visudo
):Then make sure that your user belongs to
admin
group (orwheel
).You need to define terminal/application that will read the password. There are two variants:
export SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass
vim /etc/sudoers
(Defaults visiblepw)In my case I've received this error because I wasn't specifying a command that I would like to use as root in the sudoers
Something like
/etc/sudoers.d/myuser
:worked for me
You can also create a file like "sudo_shutdown" in /etc/sudoers.d, with content:
This allows users which are in the adm group to shutdown without a password.