Skip to content

Running on Synology Docker and turn Windows 10 on off using SSH and Samba

cstosgale edited this page Aug 2, 2020 · 3 revisions

This guide explains how to get homebridge and homebridge-wol running on a Synology NAS using docker. The guide was contributed by Salvora.

Statement from Salvora. See: https://github.com/AlexGustafsson/homebridge-wol/issues/95.

I have been trying to get this work on Synology docker homebridge with a Win 10 machine using SSH and finally managed to get it working. As a linux idiot, I was really struggling. I don't know if these instructions will be able to help other people but I am posting them anyway.

Initial setup

Homebridge

  1. add Docker container startup script these lines (You can add these with with homebridge config-ui-x menu)
  2. apk add --no-cache samba samba-common-tools
  3. apk add --no-cache openssh-client
  4. Restart the docker container.

Arrange your config file:

{
  "accessory": "NetworkDevice",
  "name": "pc_name",
  "mac": "mac",
  "ip": "ip_address",
  "pingInterval": 2,
  "pingsToChange": 5,
  "pingTimeout": 1,
  "wakeGraceTime": 45,
  "shutdownGraceTime": 60,
  "shutdownCommand": "ssh -o StrictHostKeyChecking=no -i /homebridge/id_rsa username@remote_Address shutdown /s"
}

Wake On Lan on Windows 10

It is pretty basic. Check your BIOS settings if WoL is enabled. Check your win 10 network interface from device manager if the magic packets are enabled.

Shutdown Windows 10 with SSH

On the Windows machine:

  1. Enable OpenSSH Client and Server from win 10 programs and features
  2. run Services.msc and make Open SSH Server start automatically

On Homebridge:

  1. Open homebridge terminal. (You can use the terminal of homebridge config-ui-x)
  2. Generating ssh keys:
/homebridge # ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /homebridge/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /homebridge/my-key.
Your public key has been saved in /homebridge/my-key.pub.
/homebridge #
  1. Try to connect to your win10 machine with SSH from homebridge. It will ask for password but no problem: ssh username@ip_address

On the Windows machine:

  1. Navigate the homebridge folder on the NAS and copy the generated id_rsa.pub file to somewhere on your computer
  2. Launch a text editor with admin priviledges, open the file C:\ProgramData\ssh\sshd_config and comment out the lines shown below
#Match Group administrators
#AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
  1. Open id_rsa.pub with a file editor and copy the contents.
  2. Navigate to the C:\Users\username\.ssh folder.
  3. Using text editor, create a new file and paste the contents you copied before.
  4. Save this file to C:\Users\username\.ssh folder with name "authorized_keys" (no file extension). This file should be located in the C:\Users\username\.ssh.
  5. Right click authorized_keys
  6. Go to Properties\Security\Advanced
  7. Click “Disable Inheritance”, then choose “Convert inherited permissions into explicit permissions on this object”
  8. Remove all permissions on the file except for SYSTEM and your user. There should only be two entries in the list, both with “Full Control”
  9. run Services.msc and restart OpenSSH SSH Server

Now you should be able to login without password with your key pairs.

On Homebridge:

  1. Check if you can connect. You might need to specify your private key in this command. ssh -i /homebridge/id_rsa username@remote_Address
  2. Use your shutdown command ssh -o StrictHostKeyChecking=no -i /homebridge/id_rsa username@remote_Address shutdown /s

You can customize your command. Check out https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/shutdown

N.B. if your shutdown command shuts down the PC too quickly, this can cause the plugin to hang as the terminal command is unable to close cleanly. In order to resolve this, you can use /t 2, to enforce a two-second delay before the shutdown initiates, allowing the command to complete.

If you are looking to suspend your PC instead of shutting it down, use PSShutdown, which is part of PSTools: https://docs.microsoft.com/en-us/sysinternals/downloads/psshutdown. Run the command interactively as the user to accept the EULA before trying to run it over SSH. The following example will suspend the PC after a two-second timeout (to resolve the issue highlighted above):

ssh -o StrictHostKeyChecking=no -i /homebridge/id_rsa username@remote_Address "C:\Data\PSTools\psshutdown -d -t 2"