Closed guysbrown closed 5 years ago
It seems to me like the issue is much simpler than you think. I think the user does not have permissions to shutdown the computer.
On your iMac, try to open the terminal and execute the shutdown command (without ssh). You’re probably going to see a prompt for your password.
There are ways to change what commands a user can execute without sudo, try that.
Thanks for the response.
I enabled password-less sudo on both machines so don't think a password prompt would happen as the command was "sudo shutdown -h now" rather than just "shutdown -h now".
I tried to create an executable script on the iMac to try it a different way. I used osascript -e 'tell app "System Events" to shut down' instead of shutdown -h now as that shouldn't ask for a password.
I can run ssh 192.168.1.82 sudo ~/rmShutdown.sh via terminal on the Mac mini and it works fine. However when I try use it as the shutdownCommand command I get the same message.
[4/7/2019, 7:53:27 PM] [iMac] An error occured while trying to shut down "iMac" (192.168.1.xx): Error: Command failed: ssh 192.168.1.xx sudo ~/rmShutdown.sh Permission denied, please try again. Permission denied, please try again. Received disconnect from 192.168.1.xx port 22:2: Too many authentication failures Disconnected from 192.168.1.xx port 22
Thoughts?
Ensure that your SSH keys are correctly setup. If the permission issue is not on the iMac side, it’s on the other side. Notice how it repeats the error message and mentions an authentication error, typical for SSH issues.
If you have setup keys for the user, ensure that the shutdown command is run by your user by testing a shutdown command like “whoami”.
Also, thank you for posting about your findings along the way! I like to imagine that it helps others when debugging issues.
Not sure if this is related but the switch always stays On even when the iMac is sleeping! The only time it shows as Off is when the iMac has been completely shut down.
Regarding the SSH keys. It works via terminal but not via Homebridge. Could it be that it is running as a different user? I would have thought that using username@ would have sorted that?
Maybe I’ll delete the SSH keys and start from scratch.
OK, so I deleted the SSH keys and recreated them and still no joy!
I can SSH via Terminal from the Mac mini to the iMac without a password and can execute the commands without issue.
However when done through Homebridge / Homekit I still get the permissions error!
Could the “Permission denied” error be due to Homebridge’s / Node’s ability to run the SSH command rather than authenticating with the remote server? Or am I just reaching?
I am stuck!!!
Regarding the first part, this is likely due to the mac responding to pinging whilst sleeping. This is a known issue without any real solution as of now. If your interested, there are other issues around discussing this further.
As for SSH keys. Yes, the decision should be automatic if you use me@...
, if you're running as the same user as SSH looks in ~/.ssh
for keys. Usually all keys are in /Users/me/.ssh
even though it may be for SSH user someone-else
. You should try to force SSH to use specific keys by using ssh -i /Users/me/.ssh/id_rsa
(or whatever your key is called) in the shutdown command.
Awesome, that fixed it. Thanks 🙏
Now I just need to figure out how I am going to use it since the iMac responds to Ping whilst asleep!!!
At least I can see if it is on and shut it down using Homekit now :)
@guyssbrown This is a known issue due to iMacs responding to pings even when they're asleep. There are some issues you can find here which discusses the issue in depth.
When this milestone has been resolved, the issue will have been mitigated: https://github.com/AlexGustafsson/homebridge-wol/milestone/1
Closing as this is solved. Feel free to open new issues if you stumble upon further trouble.
Hey,
I am having an issue getting this working. Hopefully someone can point out where I am going wrong! PLEASE HELP!
Backstory
I am running Homebridge on a Mac mini and have this setup to wake/shutdown an iMac.
I have setup SSH so that I can SSH from the Mac mini to the iMac without a password and that works fine.
Issue
If I run the 'ssh 192.168.1.xx sudo shutdown -h now' command from terminal on the Mac mini then the iMac shutdown as expected.
However, when I attempt to toggle the switch to off I get the following:
[4/7/2019, 4:18:21 PM] [iMac] NetworkDevice shutdown cycle started for "iMac" (192.168.1.xx) [4/7/2019, 4:18:21 PM] [iMac] Attempting to shut down "iMac" (192.168.1.xx) using "ssh 192.168.1.xx sudo shutdown -h now" [4/7/2019, 4:18:21 PM] [iMac] NetworkDevice "iMac" (192.168.1.xx) went from status "Online" to "Shutting Down" [4/7/2019, 4:18:21 PM] [iMac] An error occured while trying to shut down "iMac" (192.168.1.xx): Error: Command failed: ssh 192.168.1.xx sudo shutdown -h now Permission denied, please try again. Permission denied, please try again. Received disconnect from 192.168.1.xx port 22:2: Too many authentication failures Disconnected from 192.168.1.xx port 22 [4/7/2019, 4:18:21 PM] [iMac] NetworkDevice "iMac" (192.168.1.xx) went from status "Shutting Down" to "Online"
Environment
Configuration
config.json { "accessory": "NetworkDevice", "name": "iMac", "mac": "xxxx", "ip": "192.168.1.xx", "pingInterval": 45, "wakeGraceTime": 10, "wakeCommand": "ssh 192.168.1.xx sudo caffeinate -u -t 300", "shutdownGraceTime": 15, "shutdownCommand": "ssh 192.168.1.xx sudo shutdown -h now" }
Notes
Homebridge is started via a LaunchAgent.
I have an account called 'ME' on my Mac mini, an account called 'ME' on my iMac and have set Homebridge to run under 'ME' - at least I think!
Here is the plist:
PS. The account isn't actually called 'ME' but you get the point!
Please HELP!