How to Fix the “sudo: no tty present and no askpass program specified” Error

To access and alter many of the core system settings, root user access is required in a Linux operating system. When it comes to Ubuntu, the “sudo” keyword is utilized to execute commands that require the permission of the root user. Sometimes when attempting to run a sudo command along with two other keywords that are “tty” and “askpass”, a familiar problem can occur with the statement: “sudo: no tty present and no askpass program specified”.

This article will elaborate on the reasoning behind this error and demonstrate how to resolve this issue.

How to Fix the “sudo: no tty present and no askpass program specified” Error?

Before we get to the reasoning behind these errors, it is important to understand what the “tty” and “askpass” keywords are. The “tty” (teletype) command sends data to the system and then shows the output.

Check out the example below:

How to install Kali Linux in Window...

The “askpass” command acts as a prompt to get the required information (usually a password) from the user. For information, let’s check out the main reasoning behind this error.

Reason: Running Sudo Without Password

The main reason for when this error is invoked is that the user is attempting to run a sudo command but is unable to gain access to the password. The reason that it does not have the password is that it is unable to reach a “tty” command, and it is also not able to rely on the “askpass” prompt for an automatic password entry.

Solution: Add the NOPASSWD Option to Sudoers File

The solution for resolving the error is to add the “NOPASSWD” option to your sudoers file. The Sudoers file deals with passwords and the permissions of the various users present in the system. Adding the “NOPASSWD” will not prompt and ask for a password when the “sudo tty” command is run. To add the “NOPASSWD” setting, open your sudoers file with the command shown below:

$ sudo visudo

Once the sudoers file is opened for editing, you can enable the “NOPASSWD” setting by adding the line that is shown below into the file:

%sudo  ALL=(ALL) NOPASSWD: ALL

This command will enable this option for the entire “sudo” group.

If you want this to be enabled for a specific user, simply add the following setting where the “user_name” is the name of the user for which you want to enable this setting:

user_name ALL=(ALL) NOPASSWD: ALL

Adding this line to the sudoers file will cause the sudo command to no longer request the password using any “tty” or “askpass” program.

That’s all from this guide!

Conclusion

The “sudo: no tty present and no askpass program specified” problem is invoked when the user attempts to utilize the sudo command in the terminal, but it is not able to input the password using the “tty” tool, and neither is it able to access the “askpass” program to take an automatic input for the authentication. This problem can be resolved by enabling the “NOPASSWD” settings in the sudoers file, allowing the sudo settings to be used on the account with prompting for a password. This article has demonstrated the reasoning behind this error and details how to resolve this problem.