9

I try to suspend my server using dbus and UPower. The server runs Ubuntu LucidLynx 64bit.

While everything works fine if I am sitting directly at the machine, it won't work via ssh. If I connect to the server via ssh and try to suspend the machine using dbus and upower, it gives back

dbus.exceptions.DBusException: org.freedesktop.UPower.GeneralError: not authorized

Could anyone please tell me how to configure dbus in order to allow ssh-users to suspend the machine?

2
  • btw: I DO grep and use the current dbus-session-adress...
    – Produnis
    Commented Jan 18, 2011 at 19:11
  • 2
    Can you give some details on the method you're using? What command line, tools, etc.
    – Kees Cook
    Commented Feb 23, 2011 at 9:02

2 Answers 2

12

There are two basic ways this can be done and a workaround:

Either you need to modify /usr/share/polkit-1/actions/org.freedesktop.upower.policy, set the XDG_SESSION_COOKIE environment variable to the appropriate value or use pm-suspend:

Modifying /usr/share/polkit-1/actions/org.freedesktop.upower.policy

Apply this patch:

--- /usr/share/polkit-1/actions/org.freedesktop.upower.policy.orig  2011-11-16 19:06:59.274055248 +0100
+++ /usr/share/polkit-1/actions/org.freedesktop.upower.policy   2011-11-16 19:11:15.178864922 +0100
@@ -21,6 +21,7 @@
     <defaults>
       <allow_inactive>no</allow_inactive>
       <allow_active>yes</allow_active>
+      <allow_any>yes</allow_any>
     </defaults>
   </action>
 

(To the <action id="org.freedesktop.upower.suspend"> tag/section), and it'll work too...

or

XDG_SESSION_COOKIE

When you're using the desktop, you'll see that $XDG_SESSION_COOKIE has one value, but in an ssh session, it has another. Store XDG_SESSION_COOKIE e.g. in a .dotfile or something when the desktop starts and source it in your script that needs to do it over ssh.

pm-suspend

Or you could just give up on doing it with dbus and UPower and just issue pm-suspend as root and get it over with! :-)

1
  • 1
    +1 for "just issue pm-suspend as root and get it over with!" - available from the pm-utils package. Commented Mar 15, 2018 at 22:35
5

Files under /usr/share/polkit-1/actions are not meant to be modified.

Create a file named /etc/polkit-1/localauthority/50-local.d/allow_all_ssh-users_to_upower.pkla

[Allow all ssh-users to upower]
Identity=unix-group:ssh-users
Action=org.freedesktop.upower.policy
ResultInactive=no
ResultActive=yes
AllowAny=yes
1
  • There is a typo in the answer - the last line should say ResultAny, not AllowAny. Commented Mar 29, 2018 at 12:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .