Explore information related to tty to run sudo
sudo sorry you must have a tty to run sudo - Fix it now
This article covers how to resolve the error sudo: sorry you must have a tty to run sudo which happens because the sudo command tries to execute a command that requires a tty.
To fix "sudo: sorry, you must have a tty to run sudo" error:
You have to run your ssh command as follows to avoid error that read as sudo: Sorry, you must have a tty to run sudo Error:
ssh -t hostname sudo command
ssh -t user@hostname sudo command
ssh -t user@box.example.com sudo command1 /path/to/file
The -t option force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g., when implementing menu services.
Multiple -t options force tty allocation, even if ssh has no local tty.
The requiretty option in sudoers file
The requiretty if set in sudo config file sudoers, sudo will only run when the user is logged in to a real tty.
When this flag is set, sudo can only be run from a login session and not via other means such as cron, shell/perl/python or cgi-bin scripts.
This flag is set on many distores by default. Edit /etc/sudoers, file, enter:
# visudo
Find line that read as follows:
Defaults requiretty
Either comment it out the line or delete the line:
#Defaults requiretty
Save and close the file.
