You can execute it a command without password from the commande line
$ sudo -l
User lsc may run the following commands on this host:
(root) NOPASSWD: /usr/local/bin/helloworld
$ sudo /usr/local/bin/helloworld
Now you try to run it via cron and you get
sudo: sorry, you must have a tty to run sudo
The message is clear, you need a terminal.
Either you edit your sudoers files to disable requiretty, or you just get yourself a terminal.
Maybe you tried to assign a pseudo terminal with ssh -t, but you may get an error if ssh has no local tty
Pseudo-terminal will not be allocated because stdin is not a terminal.
Don’t despair, read man ssh
Multiple -t options force tty allocation, even if ssh has no local tty.
* * * * * ssh -t -t sudo /usr/local/bin/helloworld >> /tmp/txt
This should work, providing you configured ssh keys 🙂