Sometimes when you’re trying to execute scripts remotely you may run into the error “sorry, you must have a tty to run sudo” in /var/log/secure.
This is caused because the default setting of sudoers is to require the user to have a TTY. To resolve this, you can disable that setting by doing the following:
vi /etc/sudoers
Comment out the following line:
Defaults requiretty
Another option is to use ssh -t if your command is executed via ssh remotely.