21 nov 2017

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

#Note
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

#Solution 
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/group
vi /etc/group

add a line for group shutdown and add your user name to it

poweroff:x:510:yourUserName

4. Change permissions to allow the shutdown group read and execute permission.
chmod 750 /sbin/poweroff

5. Power off can only be run by root so you need to have group "poweroff" execute the program as if you were root.
chmod u+s /sbin/poweroff

Now we have the "permission" to power off the system as admin 

6. Download plink
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 "poweroff"










Nessun commento:

Posta un commento