Posts tagged: Synology DSM poweroff reboot as admin user

Synology DSM6.x poweroff command as root user

1- We want to be able to poweroff or reboot our Synology using SSH.

remote user name: admin

remote machine name (Synology NAS): syno.lan

Prerequisite: SSH login should be password-less.

2- login to admin@syno.lan
ssh -i .ssh/id_syno admin@syno.lan
3- New sudoers entry

In order to allow ‘admin’ to execute specific commands as ‘root’, we should edit the sudoers file.

But instead of editing /etc/sudoers, which might be later edited during a system upgrade, we simply add our file into /etc/sudoers.d/

In addition on DSM6.x the sudoers file has not writable permission.

sudo vi /etc/sudoers.d/powercmds

edit as follow:

# allow user 'admin' to poweroff/reboot
Cmnd_Alias POWERCMDS = /sbin/poweroff, /sbin/reboot

User ‘admin’ can now execute POWERCMDS as ‘root’ user.

Then save and logout.

4- Test from client

To verify, without rebooting, we can just print the version:

ssh -t -i .ssh/id_syno admin@syno.lan "sudo reboot --version"

Note: switch ‘-t’ has been added. From SSH manual:

-t Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

5- Poweroff from client
ssh -t -i .ssh/id_syno admin@syno.lan "sudo poweroff"







WordPress Themes