Need help?

Our experts have had an average response time of 11.7 minutes in August 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

sudo: sorry you must have a tty to run sudo – How to resolve

by | Mar 20, 2021

Stuck with the error, sudo: sorry you must have a tty to run sudo? We can help you.

Sudo is a command-line program that allows users to run programs with the security privileges of another user or group which default to the superuser.

As part of our Server Management Services, we assist our customers with several Command-line queries.

Today, let us see how to fix this error on Linux or Unix based systems


sudo: sorry you must have a tty to run sudo

Here, TTY stands for teletypewriter. It is a command we use to provide the file name of the terminal connected to the standard input.

For example, /dev/ttys001.

We found that this error occurs when we run the following command:

ssh [email protected] sudo command1 /path/to/file

The error message stated:

sudo: sorry, you must have a tty to run sudo


sudo: no tty present and no askpass program specified

This is common to Fedora, RHEL, CentOS, many other Linux distribution, and Unix-like systems for security concerns as it shows the password in clear text format.

Moving ahead, this error occurs because the sudo command tries to execute a command that requires a tty.

This happens mostly because we run on a Linux distribution with sudo configured by default to require a tty.

Generally, this was a matter of security concern. However, in reality, this does not provide any real security benefit.

We can enforce it by setting Defaults requiretty in the /etc/sudoers.


How to solve the error?

  • Use pseudo tty

In order to avoid this error, we have to run ssh command as follows:

ssh -t hostname sudo command
ssh -t [email protected] sudo command
ssh -t [email protected] sudo command1 /path/to/file

The -t option forces pseudo-tty allocation.

We can use it to execute arbitrary screen-based programs on a remote machine, which can be very useful, for example, when implementing menu services. Multiple -t options force tty allocation, though the ssh has no local tty.

If we encounter the error “Pseudo-terminal will not be allocated because stdin is not a terminal”, then we use -tt to force a pseudo-terminal. If we do not need a pseudo-terminal, then use -T to simply disable pseudo-tty allocation.

  • The requiretty option in the sudoers file

The requiretty if set in sudo config file sudoers, will only run when the user is logged in to a real tty.

When this flag is set, sudo can only run from a login session and not via other means such as cron, shell/perl/python, or cgi-bin scripts.

Edit /etc/sudoers, file:

# visudo

Find the line that read as follows:

Defaults requiretty

Either comment it out or delete the line:

#Defaults requiretty

Eventually, save and close the file.

To run the command without using the -t option, we can use the su command instead of the sudo command:

## NOTE: RHEL/CentOS specific syntax ##
su –session-command=”/path/to/command1 arg1 arg2″

## others ##
su -c ‘/path/to/command1 arg1 arg2’


ssh [email protected] su –session-command=”/path/to/command1 arg1 arg2″
ssh [email protected] su -c ‘/path/to/command1 arg1 arg2’

We can run /scripts/job1 as bob user using the same syntax:

ssh [email protected] su –session-command=”/scripts/job1 /nas” bob


ssh [email protected] su bob -c “/scripts/job1 /nas”

Another option is to use the following syntax:

echo -e “\n”|sudo -S command

[Need help with the resolution? We’d be happy to assist]



In short, the error sudo: sorry you must have a tty to run sudo occurs because the sudo command tries to execute a command that requires a tty. Today, we saw how to solve this.


Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.


var google_conversion_label = "owonCMyG5nEQ0aD71QM";


Submit a Comment

Your email address will not be published. Required fields are marked *

Privacy Preference Center


Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]


Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid


Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie


These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.