I am trying to configure my system so that I can remotely turn it off. The command I want to execute is this one:
ssh -i $HOME/.ssh/id_rsa myuser@myserver 'sudo poweroff'
Doing this returns an error though:
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
I believe this behavior should the be same as when I login as this same user on the system (Ubuntu 24.04) and type sudo poweroff, because if I do that I am prompted for a password, which I do not want to be prompted for. I did already change sudoers using sudo visudo, telling the system to the user to use /sbin/poweroff without password, but this did not prevent the error from happening:
myuser ALL=(ALL) NOPASSWD: /sbin/poweroff
I also checked the paths using whereis poweroff resulting in:
poweroff: /usr/sbin/poweroff /usr/share/man/man8/poweroff.8.gz
Therefore, I changed the sudoers to this:
myuser ALL=(ALL) NOPASSWD: /usr/sbin/poweroff
The error persists when using SSH though and being logged into the system also prompts me for the password when entering sudo poweroff. What musst I do so that I am not prompted for any password when entering sudo poweroff?