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 🙂
Please read man sudoers instead. In particular, disabling ‘requiretty’ will get you the same result.
I wrote that
And disabling requiretty requires root access