I am writing a pyQt client-server application which restarts/shutdowns PCs remotely.
The receivers are listening to the network for incomming messages, and the sender sends a restart/shutdown message to the selected receiver.
The following part of code is running on a receiver:
import os
self.currentOS = calling a function to determine the current OS
if self.currentOS == "Win":
os.system("shutdown -r -f -t 1")
elif self.currentOS == "Lin":
os.system("shutdown -r now")
I have 2 virtual machines acting as receivers, one on Windows and the other on Linux.
When i send a restart message to the Windows receiver, the machine restarts.
When i send a restart message to the Linux receiver, it asks for password
Incoming:EXEC_OP_RESTART
[sudo] password for jwalker:
What do i have to change to overcome this?
Is shutdown -r now
the only way, or can i do this another way (more directly)?
EDIT:
In this question, something called dbus
was used, and it was done without a password, i am searching about dbus, as an alternative.
Robert :
It takes root privileges to restart a Linux machine. Some desktop environments use a daemon to get around this.... but I suggest editing the sudoers file\n\nhttps://help.ubuntu.com/community/Sudoers for a howto. Basically you'll want to allow the restart command - and only the restart command - to be run without a password.\n\nSomething like:\n\nALL ALL=(ALL) NOPASSWD: /usr/sbin/shutdown\n\n\nwill let any user on the machine restart it without using a password. You'll probably need to prefix the 'shutdown' in your system command with 'sudo', though it looks like it's being called automatically somehow. If this isn't secure enough, you can make a group, make your program run as that group, then allow that group to restart.\n\nEDIT: Apparently this can be done with DBus (note: I haven't tested this):\n\ndbus-send --system --print-reply --dest=\"org.freedesktop.Hal\" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Restart int32:0\n\n\nThis works because dbus runs as root (or has root privs) and can therefore accept requests to restart from nonpriveleged processes and act on them. I still think the sudo way is cleaner, and so will anyone who maintains this code.",
2011-11-11T03:57:20
john :
Run the script with sudo python. For example, if your file were named remotesd.py, sudo python remotesd.py",
2011-11-11T03:54:34