Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HOWTO] Remote Wake, Reboot and Shutdown
#1
Hi All,

Like many, my NAS is not easily physically accessed so a "1-button" facility to wake, reboot and shutdown the device is extremely useful. After searching the web for many options, I've narrowed it down to the simplest methods. I'm using Win7x64 and a N4800 with FW2.03.07.3.cdv but the basic principles should apply across any device and OS.

Wake Up
This is the easy bit since most Thecus NAS boxes support Wake-On-Lan (WOL).

  1. Enable WOL under the System Management tab in the NAS admin webGUI
  2. Obtain a WOL client. I'm using WakeMeOnLan by NirSoft but any facility that allows passing of commands will work equally well.
  3. Create a desktop shortcut to the WOL client and pass the relevant command and IP address. For example, mine is: "c:\program files (x86)\wakeonlan\wakemeonlan.exe" /wakeup 192.168.x.xxx

Shutdown
This is a little trickier but not that difficult. There are a few alternatives out there that require installing of modules ... this doesn't. It just uses the native Linux feature set that our boxes already have. This method will invoke the root user which is potentially a security vulnerability. There are ways to create a non-root user with power control privileges but I had major problems doing this.

  1. Enable SSH under the Network Service tab in the NAS Admin GUI
  2. I'd suggest using the default port (22) but you can change it. If you do this, make a note of it now.
  3. Download PuTTY and PuTTYgen (Google knows where these are)
  4. Open PuTTYgen and Generate a new key. Then Save private key as root.ppk in a location of your choice. Keep the PuTTYgen window open.
  5. Open PuTTY and log-in to the NAS as root (password is the admin password). Enter
    Code:
    mkdir .ssh
    . Now create a file authorized_keys (no extension) and paste the key from PuTTYgen into it. There are a variety of ways to do this. I just created the file on my PC and copied it across.
  6. I believe some versions of ThecusOS clear the contents of the root directory on reboot. Mine doesn't seem to. If this happens, you can edit /etc/ssh/sshd_config to look for the Authorized Keys file elsewhere on the system.
  7. Exit from the session and restart PuTTY
  8. On the Session tab enter the IP address of your NAS and the port number you chose to use earlier, connection type is SSH
  9. On the Connection/Data tab enter root as the auto-login username
  10. On the Connection/SSH/Auth tab Browse to the root.ppk file you created earlier
  11. On the Connection/SSH tab enter
    Code:
    /img/bin/sys_halt
    under Remote command
  12. The required command will depend on firmware used but should be pretty obvious
  13. On the Session tab enter nasshutdown (or other name of your choice) into Saved Sessions and click Save
  14. Cancel out of PuTTY
  15. Create a desktop shortcut with "C:/directory_where_your_PuTTY_lives/PuTTY.exe" -load nasshutdown

Reboot
This is very easy if you've already done the Shutdown step above

  1. Repeat all the steps above, except enter
    Code:
    /img/bin/sys_reboot
    instead of syshalt in the Remote command box


Well that's it. Let me know if it does or doesn't work for you. Of course, I take no responsibility if these crash or brick your NAS, create conflicts or problems, cause the sky to fall in etc .... Wink
Reply
#2
Hi All,

Like many, my NAS is not easily physically accessed so a "1-button" facility to wake, reboot and shutdown the device is extremely useful. After searching the web for many options, I've narrowed it down to the simplest methods. I'm using Win7x64 and a N4800 with FW2.03.07.3.cdv but the basic principles should apply across any device and OS.

Wake Up
This is the easy bit since most Thecus NAS boxes support Wake-On-Lan (WOL).

  1. Enable WOL under the System Management tab in the NAS admin webGUI
  2. Obtain a WOL client. I'm using WakeMeOnLan by NirSoft but any facility that allows passing of commands will work equally well.
  3. Create a desktop shortcut to the WOL client and pass the relevant command and IP address. For example, mine is: "c:\program files (x86)\wakeonlan\wakemeonlan.exe" /wakeup 192.168.x.xxx

Shutdown
This is a little trickier but not that difficult. There are a few alternatives out there that require installing of modules ... this doesn't. It just uses the native Linux feature set that our boxes already have. This method will invoke the root user which is potentially a security vulnerability. There are ways to create a non-root user with power control privileges but I had major problems doing this.

  1. Enable SSH under the Network Service tab in the NAS Admin GUI
  2. I'd suggest using the default port (22) but you can change it. If you do this, make a note of it now.
  3. Download PuTTY and PuTTYgen (Google knows where these are)
  4. Open PuTTYgen and Generate a new key. Then Save private key as root.ppk in a location of your choice. Keep the PuTTYgen window open.
  5. Open PuTTY and log-in to the NAS as root (password is the admin password). Enter
    Code:
    mkdir .ssh
    . Now create a file authorized_keys (no extension) and paste the key from PuTTYgen into it. There are a variety of ways to do this. I just created the file on my PC and copied it across.
  6. I believe some versions of ThecusOS clear the contents of the root directory on reboot. Mine doesn't seem to. If this happens, you can edit /etc/ssh/sshd_config to look for the Authorized Keys file elsewhere on the system.
  7. Exit from the session and restart PuTTY
  8. On the Session tab enter the IP address of your NAS and the port number you chose to use earlier, connection type is SSH
  9. On the Connection/Data tab enter root as the auto-login username
  10. On the Connection/SSH/Auth tab Browse to the root.ppk file you created earlier
  11. On the Connection/SSH tab enter
    Code:
    /img/bin/sys_halt
    under Remote command
  12. The required command will depend on firmware used but should be pretty obvious
  13. On the Session tab enter nasshutdown (or other name of your choice) into Saved Sessions and click Save
  14. Cancel out of PuTTY
  15. Create a desktop shortcut with "C:/directory_where_your_PuTTY_lives/PuTTY.exe" -load nasshutdown

Reboot
This is very easy if you've already done the Shutdown step above

  1. Repeat all the steps above, except enter
    Code:
    /img/bin/sys_reboot
    instead of syshalt in the Remote command box


Well that's it. Let me know if it does or doesn't work for you. Of course, I take no responsibility if these crash or brick your NAS, create conflicts or problems, cause the sky to fall in etc .... Wink
Reply
#3
Just a note on using the commands poweroff and reboot. These are not intended to be used directly since for a normal shutdown/reboot Thecus requires some additional tasks to be performed.

To avoid damages you should use the wrapper scripts provided with the firmware. Since the script names and their calling syntax vary between firmware versions you should use wrappers to call them. Please check out How to remotely shut down the NAS for examples.

/Falk
Further information und module downloads at FaJo.de

I decided to finally stop module development and maintenance. Existing modules are still available for download for now.
Reply
#4
Just a note on using the commands poweroff and reboot. These are not intended to be used directly since for a normal shutdown/reboot Thecus requires some additional tasks to be performed.

To avoid damages you should use the wrapper scripts provided with the firmware. Since the script names and their calling syntax vary between firmware versions you should use wrappers to call them. Please check out How to remotely shut down the NAS for examples.

/Falk
Further information und module downloads at FaJo.de

I decided to finally stop module development and maintenance. Existing modules are still available for download for now.
Reply
#5
fajo Wrote:Just a note on using the commands poweroff and reboot. These are not intended to be used directly since for a normal shutdown/reboot Thecus requires some additional tasks to be performed.

To avoid damages you should use the wrapper scripts provided with the firmware. Since the script names and their calling syntax vary between firmware versions you should use wrappers to call them. Please check out How to remotely shut down the NAS for examples.

/Falk

fajo, thanks for your hard work developing the fajosshd module. It's taken me some time to get it to work, partly because some of the guidance in your tutorial above I found was not sufficiently explicit for me. My skills with Linux are not great and the resources that I could find out there for advice didn't quite hit the target that I was after. A big factor for the disconnect is that I'm working from a Windows platform, whereas you appear to be pretty heavily into Linux and your advice is geared towards remoting into the NAS from a Linux distro of some kind.

So, for anyone wanting to make fajosshd work on a Windows platform, below is what I found worked for me.

OS Platform - Windows 10

Software / Utility Requirements
a. FajoSSHD module http://www.fajo.de/main/thecus/modules/fajosshd
b. PuTTY full suite (PuTTYgen, pageant and plink are used) http://www.putty.org/
c. Bitvise SSH Client (optional but offers GUI editor and file handling integration with Windows via an SFTP GUI) http://www.putty.org/

1. Install and enable the FajoSSHD module on the NAS (in my case an N5550 running FW 2.05.14.5 )

2. Create a Login SSH key using PuTTYgen (see pic for an example):
PuTTY Key Generator

Save the private key without (the security risk for me is not an issue because I'm dealing with shared hardware in, say, a work environment) a key password , e.g.:
privateloginkey.ppk

Select All, copy and then paste the text in the Public Key window (refer pic URL above) as a single string to a text file for safe keeping (I used notepad++ as my editor). Note the key's drive & folder location.

3. Repeat the process to generate a NAS Shutdown Key and NAS Reboot Key if you plan to remote from a Linux OS at a later stage.

4. Using the Bitvise SSH Client, login in to the NAS where NASIP is the IP address (default 192.168.1.100)

- Server:
Host > NASIP
Port > 10022
- Authentication:
Username > root
Initial method > password
Password > [password used to login to NAS using "admin" via web GUI]

Save Profile as > choose file name and folder location

Example pic here > Bitvise Xterm Login
Note that the IP for my NAS is different from the default.

5. Using the Bitvise Explorer Window (SFTP GUI), navigate to:
Code:
/raid/data/module/FaJoSSHD/system/etc/ssh/users/root/authorized_keys
(Note that the directory /raid is a symlink that will automatically change to /raid0 - nothing to worry about as far as I can tell)
... and right click / context on the file authorized_keys and select Edit with and include the file path to your favourite editor (I used notepad++ because it plays nice with Linux and has a lot of handy features and I'd also suggest you check the "make this the default" box)

Example pic here > Bitvise Explorer

6. From 2 above, copy the NAS login public key text string to create one long line of text beginning with ssh-rsa. While you're here, it couldn't hurt to include the shutdown and reboot keys along the lines of the advice given at:
http://www.fajo.de/main/thecus/modules/fajosshd

This ends up being the public key text string preceded by command="/raid/data/module/FaJoSSHD/system/sbin/wrapper.shutdown"
for the shutdown script.

I found after all my trial and error that these latter steps are not critical if you're planning to remote in from a Windows platform only. I think that it's not a bad idea to point this out for those who'll play the field and might use a Linux platform in future. For the Windows remote method used below, the NAS Login Key is mandatory.

Once you're done, save and close the file authorized_keys

For interest, you can check file permissions using the Bitvise GUI by right clicking on the file and selecting Properties > Permissions
FWIW, my file had a default permission of 0600 (i.e. Owner Read / Write)

7. To run a remote Windows CMD or batch command, then:
a. Invoke pageant and load the NAS Login Private Key that plink needs as a pre-requisite to perform a remote command call to the NAS. If you've used the full PuTTY .msi installer then it will default to add pageant and plink to your system path, so that's why the command below doesn't include the executable's file path but this only works for the CMD interface (on my machine anyway and I have messed with the system to see if I can change it):
Code:
pageant "X:\file_location_path\privateloginkey.ppk"
for a batch command, it's a simple case of entering the full file path for the executable (shown below for a default installation):
Code:
"C:\Program Files (x86)\PuTTY\pageant.exe" "X:\file_location_path\privateloginkey.ppk"

b. Next, perform the remote call using plink and the following instruction as an example of the reboot command:
Code:
plink -P 10022 root@192.168.1.100 "sh /raid/data/module/FaJoSSHD/system/sbin/wrapper.reboot"
Same comment relating to batch commands noted in 7.a. also applies.

Note the use of the case sensitive -P modifier to specify the required port as plink defaults to port 22. For testing the -v modifier, provides verbose output and I found this handy to work out where I was going wrong along the way. Both reboot and shutdown wrappers were tested and work fine on my setup.

EDIT: I can confirm that the key configuration is persistent. I've just upgraded to FW V2.06.01 and after a reboot, the pageant/plink command / batch file works fine.

8. Now crack a beer and relax as your Windows commands do the seemingly simple task of rebooting or turning off your NAS for you. It would have been nice if there was a simpler way. :roll:
Thecus N5550 (D2550 @ 1.86GHz, BIOS: CDV_T29 X64)
Disks: 5*3TB RAID-6 (5 * Western Digital Red WDC WD30EFRX-68AX9N0)
Memory: 4GB (2*2GB Kingston KVR1333D3S8S9/2G)
OS: CentOS v7.3 (1611)
Reply
#6
fajo Wrote:Just a note on using the commands poweroff and reboot. These are not intended to be used directly since for a normal shutdown/reboot Thecus requires some additional tasks to be performed.

To avoid damages you should use the wrapper scripts provided with the firmware. Since the script names and their calling syntax vary between firmware versions you should use wrappers to call them. Please check out How to remotely shut down the NAS for examples.

/Falk

fajo, thanks for your hard work developing the fajosshd module. It's taken me some time to get it to work, partly because some of the guidance in your tutorial above I found was not sufficiently explicit for me. My skills with Linux are not great and the resources that I could find out there for advice didn't quite hit the target that I was after. A big factor for the disconnect is that I'm working from a Windows platform, whereas you appear to be pretty heavily into Linux and your advice is geared towards remoting into the NAS from a Linux distro of some kind.

So, for anyone wanting to make fajosshd work on a Windows platform, below is what I found worked for me.

OS Platform - Windows 10

Software / Utility Requirements
a. FajoSSHD module http://www.fajo.de/main/thecus/modules/fajosshd
b. PuTTY full suite (PuTTYgen, pageant and plink are used) http://www.putty.org/
c. Bitvise SSH Client (optional but offers GUI editor and file handling integration with Windows via an SFTP GUI) http://www.putty.org/

1. Install and enable the FajoSSHD module on the NAS (in my case an N5550 running FW 2.05.14.5 )

2. Create a Login SSH key using PuTTYgen (see pic for an example):
PuTTY Key Generator

Save the private key without (the security risk for me is not an issue because I'm dealing with shared hardware in, say, a work environment) a key password , e.g.:
privateloginkey.ppk

Select All, copy and then paste the text in the Public Key window (refer pic URL above) as a single string to a text file for safe keeping (I used notepad++ as my editor). Note the key's drive & folder location.

3. Repeat the process to generate a NAS Shutdown Key and NAS Reboot Key if you plan to remote from a Linux OS at a later stage.

4. Using the Bitvise SSH Client, login in to the NAS where NASIP is the IP address (default 192.168.1.100)

- Server:
Host > NASIP
Port > 10022
- Authentication:
Username > root
Initial method > password
Password > [password used to login to NAS using "admin" via web GUI]

Save Profile as > choose file name and folder location

Example pic here > Bitvise Xterm Login
Note that the IP for my NAS is different from the default.

5. Using the Bitvise Explorer Window (SFTP GUI), navigate to:
Code:
/raid/data/module/FaJoSSHD/system/etc/ssh/users/root/authorized_keys
(Note that the directory /raid is a symlink that will automatically change to /raid0 - nothing to worry about as far as I can tell)
... and right click / context on the file authorized_keys and select Edit with and include the file path to your favourite editor (I used notepad++ because it plays nice with Linux and has a lot of handy features and I'd also suggest you check the "make this the default" box)

Example pic here > Bitvise Explorer

6. From 2 above, copy the NAS login public key text string to create one long line of text beginning with ssh-rsa. While you're here, it couldn't hurt to include the shutdown and reboot keys along the lines of the advice given at:
http://www.fajo.de/main/thecus/modules/fajosshd

This ends up being the public key text string preceded by command="/raid/data/module/FaJoSSHD/system/sbin/wrapper.shutdown"
for the shutdown script.

I found after all my trial and error that these latter steps are not critical if you're planning to remote in from a Windows platform only. I think that it's not a bad idea to point this out for those who'll play the field and might use a Linux platform in future. For the Windows remote method used below, the NAS Login Key is mandatory.

Once you're done, save and close the file authorized_keys

For interest, you can check file permissions using the Bitvise GUI by right clicking on the file and selecting Properties > Permissions
FWIW, my file had a default permission of 0600 (i.e. Owner Read / Write)

7. To run a remote Windows CMD or batch command, then:
a. Invoke pageant and load the NAS Login Private Key that plink needs as a pre-requisite to perform a remote command call to the NAS. If you've used the full PuTTY .msi installer then it will default to add pageant and plink to your system path, so that's why the command below doesn't include the executable's file path but this only works for the CMD interface (on my machine anyway and I have messed with the system to see if I can change it):
Code:
pageant "X:\file_location_path\privateloginkey.ppk"
for a batch command, it's a simple case of entering the full file path for the executable (shown below for a default installation):
Code:
"C:\Program Files (x86)\PuTTY\pageant.exe" "X:\file_location_path\privateloginkey.ppk"

b. Next, perform the remote call using plink and the following instruction as an example of the reboot command:
Code:
plink -P 10022 root@192.168.1.100 "sh /raid/data/module/FaJoSSHD/system/sbin/wrapper.reboot"
Same comment relating to batch commands noted in 7.a. also applies.

Note the use of the case sensitive -P modifier to specify the required port as plink defaults to port 22. For testing the -v modifier, provides verbose output and I found this handy to work out where I was going wrong along the way. Both reboot and shutdown wrappers were tested and work fine on my setup.

EDIT: I can confirm that the key configuration is persistent. I've just upgraded to FW V2.06.01 and after a reboot, the pageant/plink command / batch file works fine.

8. Now crack a beer and relax as your Windows commands do the seemingly simple task of rebooting or turning off your NAS for you. It would have been nice if there was a simpler way. :roll:
Thecus N5550 (D2550 @ 1.86GHz, BIOS: CDV_T29 X64)
Disks: 5*3TB RAID-6 (5 * Western Digital Red WDC WD30EFRX-68AX9N0)
Memory: 4GB (2*2GB Kingston KVR1333D3S8S9/2G)
OS: CentOS v7.3 (1611)
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  shutdown/reboot script in Perl for N3200 kenyap 6 3,743 04-15-2015, 05:05 PM
Last Post: teddy_b
  [HOWTO] Remote Wake, Reboot and Shutdown 0 9,251 Less than 1 minute ago
Last Post:

Forum Jump:


Users browsing this thread: 1 Guest(s)