Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot SUDO SU anymore, "no tty present and no askpass program specified"

Tags:

linux

ssh

sudo

I have a root server where I disabled login via user root and created another user that is in the sudoer list. So when I want to work on the server I do:

ssh myusername@IP_ADDRESS

On the server:

sudo su

enter my password to get root rights. This worked fine for 6 months now. Today I get this message when doing sudo su:

sudo: no tty present and no askpass program specified

What the hack is happening? What does this error mean and why do I get it?? Without root rights I cannot do so much on the server. Any idea how to fix this?

like image 323
UpCat Avatar asked Sep 24 '14 09:09

UpCat


People also ask

How do you solve sudo no tty present and no Askpass specified?

Execute a command with sudo and prompt for a password If you don't want to use an askpass command or cannot use one, then you can use sudo -S which will direct sudo to read the password from the standard input ( stdin ) instead of prompting the user for it with an askpass command.

What is Askpass in Linux?

The ssh-askpass is a generic executable name for many packages, with similar names, that provide a interactive X service to grab password for packages requiring administrative privileges to be run. It prompts the user with a window box where the necessary password can be inserted.

What is sudo Askpass?

The options are as follows: -A , --askpass Normally, if sudo requires a password, it will read it from the user's terminal. If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard output.

What is an Askpass helper?

Specifically, the error message refers to an “askpass helper”: a program, usually with a GUI, that sudo will invoke whenever it needs authentication from the user but is not running in a terminal.


2 Answers

sudo tries to open /dev/tty for read-write and prints that error if it fails. You've indicated in comments that /dev/tty is missing on your system.

Sudo has an option -S to read the password from standard input instead of /dev/tty. You should be able to run sudo -S to become root.

Regarding how to recover /dev/tty, It's possible that rebooting the server would be sufficient; the system might recreate all devices in /dev during bootup. Alternately, to create a device, you use the mknod command, but you need to know the correct major and minor numbers for the tty device. On an Ubuntu system I have available, I see these entries in /dev:

crw------- 1 root root      5,   1 Apr 16 18:36 console
crw-rw-rw- 1 root tty       5,   2 Sep 24 15:35 ptmx
crw-rw-rw- 1 root tty       5,   0 Sep 24 14:25 tty

In this case, the major number is 5 and the minor number is 0. /dev/console and /dev/ptmx have the same major number. So I'd inspect /dev/console or /dev/ptmx to find the correct major number, then run:

mknod /dev/tty c major 0

where "major" is the correct major number.

After recreating /dev/tty, make sure the permissions are correct:

chmod 666 /dev/tty
like image 65
Kenster Avatar answered Sep 23 '22 17:09

Kenster


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):

# Members of the admin group may gain root privileges.
%admin  ALL=(ALL) NOPASSWD:ALL

Then make sure that your user belongs to admin group (or wheel).

Ideally (safer) it would be to limit root privileges only to specific commands which can be specified as %admin ALL=(ALL) NOPASSWD:/path/to/program

like image 28
kenorb Avatar answered Sep 21 '22 17:09

kenorb