I'm trying to execute this script from my laptop to shutdown the server without having to enter the sudo password. (Both are running Ubuntu 14.04.2 LTS)

ssh -t lachlan@192.168.0.xxx sudo shutdown -h now


lachlan@lachlan-MacBookAir:~/.scripts$ ./optiplex_990_shutdown.sh
[sudo] password for lachlan: 
Connection to 192.168.0.xxx closed.

As you can see it still asks for password. The following lines are included in the sudoers file edited using sudo visudo.

Cmnd_Alias SHUTDOWN_CMDS = /sbin/poweroff, /sbin/halt, /sbin/reboot
lachlan lachlan-MacBookAir= NOPASSWD: SHUTDOWN_CMDS

The output from sudo -l is

User lachlan may run the following commands on ubuntu:
(ALL) NOPASSWD: /sbin/poweroff, /sbin/halt, /sbin/reboot
(ALL : ALL) ALL

BTW lachlan is also the username for admin on the server

I've also tried to run the following

ssh lachlan@192.168.0.xxx dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

and i get the following in terminal

Error org.freedesktop.ConsoleKit.Manager.NotPrivileged: Not Authorized

I would prefer to use the second method dbus-send and I have this working for my intel NUC running Kodibuntu but the Ubuntu server must be more secure in some way. BTW I've set up Key-based authentication for ssh connections so it's not that asking me for the password.

Thanks in advance. Apologies for the bad formatting in this post (first question)

I've compared the contents of
/usr/share/polkit-1/actions/org.freedesktop.consolekit.policy
on both machines, the intel nuc running kodibuntu and the optiplex 990 running ubuntu server and they're both the same. So it must be that there are multiple user logged in right? No. I tried logging multiple user in to the nuc via ssh from 2 other laptops and checked with who -a. Then I ran the following script
ssh lachlan@192.168.0.xxx dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
No problem, all works. I logged the same 2 computers in to the ubuntu server and ran the same script and I get
Error org.freedesktop.ConsoleKit.Manager.NotPrivileged: Not Authorized

Ok. From terminal on each machine just to eliminate any stupid mistakes I might be making I entered the command
dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
and same result. So on kodibuntu you don't have to be admin and on ubuntu server you do. How do you change that & should I?

  • In case you do run dbus services try with login manager rather than consolekit: askubuntu.com/a/454077/3940 – Takkat Jun 21 '15 at 9:06
  • Thanks Takkat. I tried the following from the link. ssh -t lachlan@192.168.0.xxx dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.PowerOff" boolean:true In terminal I get a similar permissions problem lachlan@lachlan-MacBookAir:~/.scripts$ ./optiplex_990_shutdown.sh Error org.freedesktop.DBus.Error.AccessDenied: Operation not permitted Connection to 192.168.0.xxx closed. When I ssh in and try sudo any of these methods they all work, it just doesn't work remotely yet without sudo and password for shutting down the server – Lachlan Forrest Jun 21 '15 at 21:04

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.