我想编写一个脚本,在以访客用户身份登录时重新启动计算机。我知道这是可能的,因为 guest 用户可以通过右上角的设置按钮关闭。
但是,当我尝试从脚本或终端运行 reboot
时,我得到了 reboot: Need to be root
。我无法使用 sudo
,因为 guest 用户没有 sudo 访问权限。
为什么当关机按钮能够以访客身份重新启动系统时,reboot
不起作用?
最佳答案
登录 session 由 systemd-logind
处理,它以 root 身份运行并允许您向其发出重启信号。这就是图形重启按钮的作用。
你 can signal it from the command line还有:
dbus-send --system --print-reply \
--dest=org.freedesktop.login1 /org/freedesktop/login1 \
"org.freedesktop.login1.Manager.Reboot" boolean:true
reboot
命令尝试自行重启系统,无需 systemd-logind
的帮助。因此它失败了,因为您无法授予它根访问权限。
关于linux - 以访客用户身份登录时,如何以编程方式重启 Ubuntu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30173119/