I am using a shutdown timer to shutdown my computer after I fall asleep. Sometimes I forget to activate the timer so I downloaded a phone app that can send an ssh command to my computer to do the shutdown.
The ssh connection works fine but the shutdown command does not work showing this error:
Failed to set wall message, ignoring: Interactive authentication required.
Failed to power off system via logind: Interactive authentication required.
Failed to open initctl fifo: Permission denied
Failed to talk to init daemon.
If I manually ssh in I can shutdown as long as I enter my password interactively.
My question is this: How can I use the shutdown/poweroff command from ssh in a non-interactive way?
This doesn’t exactly answer your queston, but do you want it to shut off at the same time every day? Or does it need to vary? Setting up a cron job might be the easiest if that’s the case.
You should use authentication with public key, instead of password.
This kind of authentication does not require password.
I think that he is able to ssh to the host. Isn’t it? Then the issue is with the shutdown command. Using sudo, a password is required.
A solution could be to configure sudo in order to don’t ask for a password for the shutdown/halt command. I don’t remember what are other ways to allow a regular user to shutdown the computer.
I can shutdown with no password required from a desktop terminal. However, from ssh I need to use sudo to get shutdown to work. Because of this my phone app that sends ssh commands does not work because it doesn’t support interactively entering the password.
From what has been said here, I feel like I should look into using public key authentication. Thanks for the assistance.
I considered that but I do not always go to sleep at the same time.
Apart ssh keys.
The password asked from the phone app is the sudo one or the password for ssh? I mean, are you able to login via ssh? Sorry but it is not clear to me.
The app takes an ip address and ssh password or an encryption key. It then takes a command to execute on the computer. The app then provides a button to push that executes the command on the computer. The app is working as expected, however it seems it has no way to get the sudo password if I use sudo inside the command.
I can reproduce this with a normal ssh from the command line. If I log in from the terminal I can run shutdown/poweroff etc without needing to use sudo. If I log in using ssh and try to use the shutdown command I get the error messages I posted. On that same ssh session if I use sudo and enter the password interactively then shutdown will work.
I feel like this is a security feature that may be getting in my way a bit but I’m not completely sure.
OK. So using the key authentication in ssh will not solve your problem.
You need to configure sudo in order to don’t ask for a password for the shutdown command.
Something like this: create a file in
sudo vi /etc/sudoers.d/haltnopwd
Put a line like this (substitute user with your username):
user ALL=(ALL) NOPASSWD: /sbin/shutdown
It has error-checking! It preventing “breaking” of sudo!
Thank you so much @alciregi, for sticking with this thread even after I mistakenly marked another answer as the solution . This answer worked perfectly!
For anyone in the future who reads this you still need to use sudo in the shutdown command but it wont ask for the password.
My question is what is the app on your phone?
It is a very simple Android app called SSH Button by David Grootendorst.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.