14 apr 2021

Poweroff Linux based NAS (Synology, ecc) remotely from Windows by command line

#Note - Updated 14/04/2021 
I had to turn off the NAS automatically after a Veeam backup copy process, but... it's not as simple as I thought.
The problem is that Linux SSH security permit executing of the "power off" command only as root and then root can not login to SSH

how do to do?

#Product affected / related 
NAS Linux based, Linux and Windows Server and Clients

1. Login to your NAS as admin user by SSH (PuTTY)

To enable ssh on Synology:
Control Panel > Terminal & SNMP > Terminal allows your Synology NAS to support Telnet and SSH command-line interface services. You can also change the security level of the SSH encryption algorithm.
To enable Telnet/SSH service:
Check the box next to the SSH protocol
Click Apply

2. Take permission as root
sudo su - or sudo -i

3.  Edit /etc/sudoers
vi /etc/sudoers

4: Add the following line 
## Admin user group is allowed to execute halt and reboot 
userOrGroup ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff

6. Download plink (Now as part of putty)

On Windows, you have to download plink from PuTTY download page and save it in a folder.
This is the command that resolve the problem:

plink.exe -ssh -t -pw “yourpassword” admin@xxx.xxx.xxx.xxx "sudo poweroff"

1 commento:

  1. Couldn't do this myself for a long time. Thanks for the guide!